PHP upload Large file failure reasons and strategies, _php tutorial

Source: Internet
Author: User

PHP upload Large file failure reasons and Countermeasures,


Why uploading large files always fails, but uploading small files is no problem. Small series also cannot its solution, search the reason on the net, collated a piece about PHP upload big file failure reason and solution article, share to everybody.

The following are various reasons and solutions:
1th Case: The temporary directory where the file is uploaded must be open and is a directory that the PHP process owner user can write . If not specified, PHP uses the system default value.
In the php.ini file, Upload_tmp_dir is used to describe the temporary directory in which PHP uploads files, and to upload files, ensure that the server does not have the temporary files closed and has permission to write to the folder.

2nd case: the value of the max_execution_time must be large enough . The variable max_execution_time sets the time at which PHP waits for the script to complete before forcing the script to terminate, which is calculated in seconds. This variable is useful when the script enters an infinite loop state. However, this feature also causes the operation to fail when there is a legitimate activity that takes a long time to complete, such as uploading large files. In such a case, you must consider increasing the value of this variable to prevent PHP from closing the script when the script is performing some important procedure, for example, setting to 90 seconds.
Max_execution_time = 90
Note that there is also a set_time_limit function in the PHP function, and the function of the above setting is the same, the difference is that the above is set in the php.ini file, and Set_time_limit is written in the PHP file. So you can also set the maximum execution time of the program by using Set_time_limit in the page, such as Unlimited: Set_time_limit (0);

3rd case: file_uploads = On default valueis on, which means that file upload via HTTP is allowed, this option cannot be set to OFF.

4th case: upload_max_filesize = 2M Sets the maximum size of the file upload, the default file upload size in the php.ini configuration file is 2M, PHP Beginners Easy to make a mistake is to write the file upload function by setting the maximum size of the upload file form area, that is, allow the maximum upload file, max_file_size (hidden range) value to specify the size of the upload file, in fact, others can bypass this value, so security, It is best to configure the Upload_max_filesize option in the php.ini configuration file to set the file upload size. The default upload_max_filesize = 2M, that is, the file upload size is 2M, if you want to upload more than 8M files, such as 20M, you must set upload_max_filesize = 20M.

5th case: Post_max_size This value must also be large enough . This variable is also a variable associated with the form submission, which limits the maximum amount of data the PHP program can receive when the client submits a form submission with the Post method. In general, the value of this value is set slightly larger than upload_max_filesize, such as to upload 20MB of files, this value can be set to 21MB.

6th case: max_input_time This variable can be used in seconds to limit the time it takes to receive data by post, get, and put . If your application is running in an environment where the network is slow, you need to increase this value to increase the time it takes to receive data, such as setting this value to 90 seconds.
Max_input_time = 90

7th case: Memory_limit must also be large enough that PHP allows you to define memory usage limits in order to avoid running scripts that use the system's available memory heavily. The Memory_limit variable is used to specify the maximum amount of memory that a single script program can use. The value of the variable memory_limit should be appropriately greater than the value of post_max_size.

8th situation: In addition if your host is the Nginx operating system, if the above operation is not possible, remember in the Nginx configuration file and add client_max_body_size 20m; Such a sentence, that is, the maximum allowed to upload 20MB, specifically according to their own circumstances. The location of my nginx configuration file is in/usr/local/nginx/conf/nginx.conf.

After reading this article you should probably know the reasons for the large file upload failure, I hope this article can provide some ideas for you to better solve similar problems.

http://www.bkjia.com/PHPjc/1063240.html www.bkjia.com true http://www.bkjia.com/PHPjc/1063240.html techarticle PHP Upload Large file failure reasons and Countermeasures, why upload large files always fail, but upload small files there is no problem. Small series also cannot its solution, search the reason on the net, tidy up ...

  • Related Article

    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.