File Upload in PHP

Google Advertisements

Prev Tutorial 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.


file_uploads = On


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.


<!DOCTYPE html>

<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"/>




$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!";  
  echo "Sorry, file not uploaded, please try again!";  


Prev Tutorial Next Tutorial

Download Projects

Adsense Advertisements
Free Classified Site – Bedpage

Yahoo Ads Advertisements