Why php fails to upload a large file and how to deal with it. _ PHP Tutorial

Source: Internet
Author: User
Reasons for failure of uploading large files in php and countermeasures ,. Why does php fail to upload large files and how to deal with them? why does it always fail to upload large files, but there is no problem with uploading small files. I cannot solve the problem by searching for the reasons on the Internet, and sorted out the reasons why php failed to upload large files and the countermeasures,

Why does it always fail to upload large files, but it is okay to upload small files. I can't explain the cause of my failure. I searched for the cause on the Internet, sorted out an article about the failure of uploading large files in php, and shared it with you.

The reasons and solutions are as follows:
1st cases:The temporary directory for storing files during file Upload must be an enabled directory that can be written by the PHP process owner.. If this parameter is not specified, PHP uses the default value.
In the php. ini file, upload_tmp_dir is used to describe the temporary directory of the files uploaded by PHP. to upload files, you must ensure that the server has no permission to close the temporary files and write the files to the folder.

2nd cases:The value of max_execution_time must be large enough.. The max_execution_time variable sets the time for PHP to wait for the script to be executed before the script is forcibly terminated. The time is calculated in seconds. This variable is useful when the script enters an infinite loop state. However, when there is a legal activity that takes a long time to complete (such as uploading large files), this function will also cause operation failure. In this case, you must consider increasing the value of this variable to prevent PHP from disabling the script when the script is executing an important process, for example, setting it to 90 seconds.
Max_execution_time = 90
Note:There is also a set_time_limit function in the php function, which serves the same purpose as the above settings. The difference between the two is that the above is in php. in the ini file, while set_time_limit is written in the PHP file. Therefore, you can also set the maximum execution time of the program by using set_time_limit on the page, for example, unlimited: set_time_limit (0 );

3rd cases:File_uploads = On. The default value is on.This option cannot be set to OFF.

4th cases:Upload_max_filesize = 2 M sets the maximum file upload size. the default file upload size in the php. ini configuration file is 2 M.An easy mistake for php beginners is to set the form area of the maximum size of the uploaded file when writing the file upload function, that is, to allow the maximum size of the uploaded file, max_file_size (hidden value range) to specify the size of the uploaded file. In fact, this value can be bypassed by others. for security reasons, it is best to set the value in php. configure the upload_max_filesize option in the ini configuration file to set the file upload size. The default upload_max_filesize = 2 M, that is, the file size is 2 M. If you want to upload files larger than 8 M, such as 20 M, you must set upload_max_filesize = 20 M.

5th cases:The value post_max_size must be large enough.. This variable is also a variable related to form submission. it limits the maximum data size that the PHP program can receive when the client submits a form through the POST method. Generally, set this value to a value slightly greater than upload_max_filesize. for example, to upload a 20 MB file, set this value to 21 MB.

6th cases:Max_input_time this variable can be used in seconds to limit the time when data is received through POST, GET, and PUT.. If the application is running in a slow network, you need to add this value to increase the time required to receive data. for example, you can set this value to 90 seconds.
Max_input_time = 90

7th cases:Memory_limit must be large enoughTo avoid using a large amount of available system memory for running scripts, PHP allows you to define the memory usage limit. Use the memory_limit variable to specify the maximum memory capacity that a single script program can use. The value of the variable memory_limit should be greater than the value of post_max_size.

8th cases:If your host is an nginx operating system, if none of the above operations work, rememberAdd client_max_body_size 20 m to the nginx configuration file;This statement indicates that the maximum upload capacity is 20 MB. The location of my nginx configuration file is/usr/local/nginx/conf/nginx. conf.

After reading this article, you should probably know the cause of the failure of uploading large files. I hope this article will provide you with some ideas to better solve similar problems.

Upload: Why does the upload of large files always fail, but it is okay to upload small files. I can't explain it. I searched the internet for the reason and sorted it out...

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.