When you do a simple form upload test, the$_files array is empty in the PHP script on the server, so you can't get the information uploaded from the browser. What's the reason?
Through Google, find the following PHP upload file $_files array is empty solution:
When using PHP to upload files in the application, when printing $_files in the background to find an empty array, this problem may have the following two reasons:
form type reason or PHP Setup problem:
- Form type
The type of form encoding to upload the file must be set to Enctype= "Multipart/form-data", because to transmit big data, the general way of submission with post
- PHP Setup issues:
PHP default post_max_size is 2M. If the POST data size is larger than post_max_size, the $_post and $_files Super Global variables will be empty. The workaround is to:
- Generic file uploads, unless the file is small. Like a 5M file, it's likely to take more than a minute to upload. In PHP, however, the default maximum execution time for this page is 30 seconds. That means more than 30 seconds, the script stops executing. This results in a situation where the Web page cannot be opened. At this point we can modify the Max_execution_time in php.ini to find the max_execution_time default is 30 seconds. Change to Max_execution_time = 0 (modifiable range is PHP _ini_all) 0 means no Limit
Or in the php file header set Ini_set (' Max_execution_time ', 0);
- Modify Post_max_size to set the maximum allowable size for post data. This setting also affects file uploads. Find post_max_size. Change to Post_max_size = 150M (modifiable range is php_ini_php_ini_perdir)
- A lot of people will change the second step. However, the maximum number of files uploaded is still 8M. Why, we're going to change one. The parameter upload_max_filesize indicates the maximum size of the uploaded file. Find Upload_max_filesize, default is 8M to Upload_max_filesize = 100M (modifiable range is php_ini_php_ini_perdir)
Another thing to note is that Post_max_size is the size of the entire expression, and upload_max_filesize is the size of the uploaded file, the former should be greater than the latter.
Why $_files arrays are empty when using PHP to process post uploads