PHP $_FILES Array (HTTP File Upload variables) (original) (raw)

Last Updated : 09 Aug, 2024

How does the PHP file handle know some basic information like file-name, file-size, type of the file and a few attributes about the file that has been selected to be uploaded? Let’s have a look at what is playing behind the scene. ****$_FILES** is a two-dimensional associative global array of items that are being uploaded via the HTTP POST method and holds the attributes of files such as:

Attribute Description
[name] Name of file which is uploading
[size] Size of the file
[type] Type of the file (like .pdf, .zip, .jpeg…..etc)
[tmp_name] A temporary address where the file is located before processing the upload request
[error] Types of error occurred when the file is uploading

Now see How does the array look like??

****$_FILES[input-field-name][name]**
****$_FILES[input-field-name][tmp_name]**
****$_FILES[input-field-name][size]**
****$_FILES[input-field-name][type]**
****$_FILES[input-field-name][error]**

**Approach: Make sure you have XAMPP or WAMP installed on your machine. In this article, we will be using the XAAMP server.

Let us go through examples, of how this PHP array works in the first example.

**Example 1 :

HTML `

"; print_r($_FILES); echo "

`

In the above script, before uploading the file

Once when we select the file and upload then the function **print_r will display the information of the PHP superglobal associative array $_FILES.

output array

**Example 2: Add the HTML code followed by PHP script in different files. Let’s make an HTML form for uploading the file **index.html

HTML `

PHP $_FILES Array