File Upload in PHP

Advertisements

String Function in PHP Next Tutorial

File Upload in PHP

PHP allows you to upload single and multiple files through few lines of code only. PHP file upload features allows you to upload binary and text files both. Moreover, you can have the full control over the file to be uploaded through PHP authentication and file operation functions.

file upload in php

First, ensure that PHP is configured to allow file uploads. In your "php.ini" file, search for the file_uploads directive, and set it to On.

Syntax

file_uploads = On

PHP $_FILES

The PHP global $_FILES contains all the information of file. By the help of $_FILES global, we can get file name, file type, file size, temp file name and errors associated with file.

  • $_FILES['filename']['name'] It returns file name.
  • $_FILES['filename']['type'] It returns MIME type of the file.
  • $_FILES['filename']['size'] It returns size of the file (in bytes).
  • $_FILES['filename']['tmp_name'] It returns temporary file name of the file which was stored on the server.
  • $_FILES['filename']['error'] It returns error code associated with this file.

uploadform.html

<!DOCTYPE html>
<html>
<body>

<form action="uploader.php" method="post" enctype="multipart/form-data">
    Select File:  
    <input type="file" name="fileToUpload"/>
    <input type="submit" value="Upload Image" name="submit"/>
</form>

<body>
<html>

uploader.php

<?php

$target_path = "c:/";  
$target_path = $target_path.basename( $_FILES['fileToUpload']['name']);   
  
if(move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $target_path)) 
{  
    echo "File uploaded successfully!";  
}
else
{
  echo "Sorry, file not uploaded, please try again!";  
}  

?>

String Function in PHP Next Tutorial

Advertisements

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 8076671483

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

Download Projects

Advertisements


Buy Websites 9999595223

Buy Fresh and Payment Receive Media.net Account with Website. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs