Skip to content
Related Articles
Get the best out of our app
Open App

Related Articles

How to get uploaded file information in Receiving Script in PHP ?

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

In this article, we will know how to get the uploaded file information in the receiving script in PHP.

When a document/file is uploaded to any application or any browser and to know the basic information of a file like a file name, type of file, and how many bytes are present in the file, PHP offers a predefined array called $_FILES that allows the receiving script to get the information of file/document. Let’s look into that process in detail.

When any document is uploaded from a web browser then it will be received by the webserver. The web server calls the PHP script specified in the form action attribute to process the file. The action attribute in the form tag defines the action to be performed when a form is submitted. Let’s visualize the process flow in the picture which is given below:

Process flow

To get the basic information of the uploaded files, PHP provides a $_FILES predefined array which is explained below in detail.

$_FILES Array: The $_FILES is a predefined & two dimensional associative global array that helps to receive a script to get the information about the uploaded file via the HTTP post method. It provides basic information about files like filename, size of the file, type of the file, etc. In receiving script the uploaded file information is organized in the $_FILES array as a two-dimensional array.

Let’s look how data of uploaded file is organized in $_FILES 2-dimensional array:

  • $_FILES[input-field-name][‘name’]: This shows the original file name on the system browser.
  • $_FILES[input-field-name][‘tmp_name’]: This shows the file with temporary file name, to be uploaded from browser was stored in the server.
  • $_FILES[input-field-name][‘type’]: This shows the file type which is determined by the web browser.
  • $_FILES[input-field-name][‘size’]: This specifies the number of bytes present in content of file.
  • $_FILES[input-field-name][‘error’]: This shows the error code associated with the uploaded file.


  • Create a HTML Form that will accept normal text file.
  • Create a PHP file that will stores the uploaded file information using $_FILES array.
  • Specify the created PHP file at action attribute inside <form> tag.
  • Upload any file from the created web page.

We will understand the concept through the example, which accepts a file to upload and print the details of file uploaded.

Example: In this example, we have created a Form that accepts normal text file. This file will be upload followed by a PHP script which is able to handle the file uploading system.


<!DOCTYPE html>
<title>Getting the file information</title>
  <h1> Upload File Here</h1>
  <form action="getFileInfo.php" 
      <input type="file" 
      <input type="submit" 

Below is the getFileInfo.php script that handle the file uploading system.

Filename: getFileInfo.php


    // Check if file was uploaded without errors
    if (isset($_FILES["simplefile"]) && $_FILES["simplefile"]["error"] == 0) {
       $file_name     = $_FILES["simplefile"]["name"];
       $file_tmp_name = $_FILES["simplefile"]["tmp_name"];
       $file_type     = $_FILES["simplefile"]["type"];
       $file_size     = $_FILES["simplefile"]["size"];
       $file_error    = $_FILES["simplefile"]["error"];
       echo "Uploaded File Name-" . $file_name . "<br>";
       echo "Temporary File Name-" . $file_tmp_name . "<br>"
       echo "Type of File-" . $file_type . "<br>";
       echo "Number of bytes-" . $file_size . "<br>";
       echo "Error-" . $file_error . "<br>";     



Note: We can upload any text file or any normal file to perform this task.

My Personal Notes arrow_drop_up
Last Updated : 06 Apr, 2023
Like Article
Save Article
Similar Reads
Related Tutorials