Why $_files arrays are empty when using PHP to process post uploads

Source: Internet
Author: User
Tags php script

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:

      1. 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
      2. 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:
        1. 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);
        2. 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)
        3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.