Home > Article > Backend Development > How to upload files using $_FILES in PHP
In PHP, you can complete the processing of uploading single and multiple files with just a few lines of code. PHP file upload feature allows uploading binary and text files. Additionally, you have complete control over the files being uploaded via PHP authentication and file manipulation features.
$_FILES in PHP
PHP global$_FILES
contains all the information of the file. With the help of $_FILES
global variables we can get the file name, file type, file size, temporary file name and file related errors.
PHP $_FILES is a predefined array used to obtain information about files uploaded through the POST method. If uploading a single file, then $_FILES
is a two-dimensional array; if uploading multiple files, then $_FILES
is a three-dimensional array.
1. Create a file.html
demo upload file, the code is as follows:
<html> <head></head> <body></body> <form enctype="multipart/form-data" action="file.php" method="POST"> Send this file: <input name="userfile" type="file" /> <input type="submit" value="Send File" /> </form> </html>
2. Create a new ## for receiving file information #PHP File
file.php, the code is as follows:
<?php echo "<pre class="brush:php;toolbar:false">"; print_r($_FILES); ?>3. After selecting the file on the
file.html page, click
Send File button will output the following information on the page:
Array ( [userfile] => Array ( [name] => 5a16984f62bc8364.jpg [type] => image/jpeg [tmp_name] => C:\Windows\php3F2.tmp [error] => 0 [size] => 47611 ) )Recommended: "
php video tutorial" "php tutorial"
The above is the detailed content of How to upload files using $_FILES in PHP. For more information, please follow other related articles on the PHP Chinese website!