---
title: "File Upload in PHP"  
description: "$_FILES is a superglobal variable in PHP. It consists of 5 variable:   $_FILES[‘file’][‘tmp_name’] – the uploaded file in the temporary directory on t"  
author: "zack mathews"  
published: 2016-06-07  
updated: 2018-03-15  
canonical: https://www.mindstick.com/blog/11145/file-upload-in-php  
category: "php"  
tags: ["php", "file", "upload"]  
reading_time: 1 minute  

---

# File Upload in PHP

**$_FILES is a superglobal [variable](https://www.mindstick.com/articles/1807/objective-c-data-types-variables-object-creation) in PHP. It consists of 5 variable:**\

- $_FILES[‘file’][‘tmp_name’] – the [uploaded file](https://www.mindstick.com/forum/137/how-to-check-uploaded-file-type-using-asp-dot-net) in the [temporary](https://www.mindstick.com/forum/2292/how-to-set-temporary-path-of-jdk-in-windows) [directory](https://www.mindstick.com/forum/226/how-to-get-application-directory-using-c-sharp-csharp) on the [web server](https://www.mindstick.com/articles/23199/digital-personal-server-the-premium-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](https://www.mindstick.com/interview/1730/what-is-mime-type-of-json) 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](https://www.mindstick.com/forum/166/webservice-method)=”post”.

- The form also need the [attribute](https://www.mindstick.com/blog/221/attributes-reflection): enctype =”multipart/form-data”. It specifies which [content](https://www.mindstick.com/articles/13019/get-the-best-content-marketing-pricing-packages-for-your-brand) is to be used while submitting the form.

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

```
<html>

   <body>



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

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

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

      </form>



   </body>

</html>
```

\
**Step 2:**Create [image](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character).php

```
<?php

if(isset($_POST["submit"]))

{

move_uploaded_file($_FILES["image"]["tmp_name"],"../user/".$_FILES["image"]["name"]);

?> // upload the file in user folder.

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

<?php

}

?>
```

---

Original Source: https://www.mindstick.com/blog/11145/file-upload-in-php

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
