PHP upload large files always fail how to solve?

Source: Internet
Author: User
PHP upload large files are always not uploaded, but upload small files there is no problem. At first I can not think of its solution, and finally on the Internet to check the relevant information, sorting out a PHP upload big file failure reasons and solutions to the article, share to everyone, I hope you can like.

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 can be written by the user of the PHP process owner. 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 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 value is 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, PHP.ini the default file upload size in the config file for 2m,php beginners is prone to make a mistake when writing the file upload function by setting the maximum size of the upload file area, that is, the maximum number of files allowed to upload, max_file_ The value of size (hidden range) to specify the size of the upload file, in fact, people can generally bypass this value, so security, it is best to configure the Upload_max_filesize option in the php.ini configuration file, 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: The value of post_max_size 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: The Memory_limit must also be large enough to prevent the running script from using the system's available memory in large quantities, and PHP allows you to define memory usage limits. 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 Nginx operating system, if the above operation is not possible, remember in the Nginx configuration file with client_max_body_size 20m; Such a sentence, that is, the maximum allowed to upload 20MB, Specific according to their own circumstances. The location of my nginx configuration file is in/usr/local/nginx/conf/nginx.conf.

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.