Tuesday, May 26, 2026
HomeLanguagesHow to access actual name of uploaded file in PHP ?

How to access actual name of uploaded file in PHP ?

In PHP, we can access the actual name of the file which we are uploading by keyword $_FILES[“file”][“name”].

  • The $_FILES is the by default keyword in PHP to access the details of files that we uploaded.
  • The file refers to the name which is defined in the “index.html” form in the input of the file.
  • The name refers to the actual name of the file.

In this article, we understand how to extract the actual name.

Example: There is a form in the “index.php” file which takes a file as input and then sends it to “file.php” using the POST method and there we can find the name and all other details of the file by using the $_FILES. Always make sure to write the correct name of the file in which you want to send the data. In this, we send the file from “index.php” to “file.php”.

index.php




<!DOCTYPE html>
<html>
  
<body>
    <form action="file.php" method="post" enctype="multipart/form-data">
        Select file to upload:
        <input type="file" name="file"><br>
        <input type="submit" value="Upload file" name="submit">
    </form>
</body>
</html>


file.php




<?php
  
    // Stores the file name
    $name = $_FILES["file"]["name"];
  
    // Store the file extension or type
    $type = $_FILES["file"]["type"];
  
    // Store the file size
    $size = $_FILES["file"]["size"];
  
    echo "File actual name is $name"."<br>";
    echo "File has .$type extension" . "<br>";
    echo "File has $size of size"."<br>";
  
?>


Output:

RELATED ARTICLES

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6892 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12107 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS