- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
The global predefined variable $_FILES is an associative array containing items uploaded via HTTP POST method. Uploading a file requires HTTP POST method form with enctype attribute set to multipart/form-data.
$HTTP_POST_FILES also contains the same information, but is not a superglobal, and now been deprecated
The _FILES array contains following properties −
$_FILES['file']['name'] - The original name of the file to be uploaded.
$_FILES['file']['type'] - The mime type of the file.
$_FILES['file']['size'] - The size, in bytes, of the uploaded file.
$_FILES['file']['tmp_name'] - The temporary filename of the file in which the uploaded file was stored on the server.
$_FILES['file']['error'] - The error code associated with this file upload.
Following test.html contains a HTML form whose enctype is set to multiform/form-data. It also has an input file element which presents a button on the form for the user to select file to be uploaded.
<form action="testscript.php" method="POST" enctype="multipart/form-data"> <input type="file" name="file"> <input type ="submit" value="submit"> </form>
The PHP script is as follows:
<?php echo "Filename: " . $_FILES['file']['name']."<br>"; echo "Type : " . $_FILES['file']['type'] ."<br>"; echo "Size : " . $_FILES['file']['size'] ."<br>"; echo "Temp name: " . $_FILES['file']['tmp_name'] ."<br>"; echo "Error : " . $_FILES['file']['error'] . "<br>"; ?>
This will produce following result −
Filename: hello.html Type : text/html Size : 56 Temp name: C:\xampp\tmp\php32CE.tmp Error : 0
- How to download large files through PHP script?
- How to upload large files above 500MB in PHP?
- PHP: Unlink All Files Within A Directory, and then Deleting That Directory
- How to upload multiple files and store them in a folder with PHP?
- Why does C++ have header files and .cpp files?
- Multiple .java files
- How to Copy files or Folder without overwriting existing files?
- Using Option Files for MySQL programs? Usage of Option Files
- How to convert PDF files to Excel files using Python?
- How to display files/folders including hidden files/folders in PowerShell?
- What are the text files and binary files in C language?
- Temporary files in Java
- Jar files in Java
- PHP php://
- Java program to delete all the files in a directory recursively (only files)
- List files recursively in C#