Home > DeveloperSection > Blogs > File Upload in PHP

File Upload in PHP

PHP PHP  File  Upload 
1 Comment(s)
 276  View(s)
Rate this:

File Upload in PHP

$_FILES is a superglobal variable in PHP. It consists of 5 variable:

·         $_FILES[‘file’][‘tmp_name’] – the uploaded file in the temporary directory on the web server.

·         $_FILES[‘file’][‘name’] – the name of the file which is uploaded.

·         $_FILES[‘file’][‘size’]-the size of the uploaded file.

·         $_FILES[‘file’][‘type’]-the MIME type of the uploaded file.

·         $_FILES[‘file’][‘error’]-the error will be shown.


Step 1: Create a form. While creating a form some rules must be follow:

·         The form must uses a method=”post”.

·         The form also need the attribute: enctype =”multipart/form-data”. It specifies which content is to be used while submitting the form.

·         NOTE: In <input> tag “file” must be given.





      <form action=”image.php” method="POST" enctype="multipart/form-data">

         <input type="file" name="image" />

         <input type="submit" name="submit"/>






Step 2: Create image.php





?> // upload the file in user folder.

 <img src="<?php echo $_FILES["image"]["name"];?>" width="300px" height="200px">//preview your image




helpful post

By Sunil Singh on   one month ago
I would like to appreciate you for this helpful post

Don't want to miss updates? Please click the below button!

Follow MindStick