Analysis of PHP large file upload problems php large file upload configuration reference

Source: Internet
Author: User
Tags form post php file upload
Analysis of PHP large file upload problems php large file upload configuration reference
When uploading large files in php programming, it always fails because php has a size limit on file upload. here is a solution for your reference.

Parameters involved in php file upload: 0: temporary directory for storing files during File upload. It must be a directory that can be written by the PHP process owner. If this parameter is not specified, PHP uses the default value of upload_tmp_dir in the php. ini file to describe the temporary directory of the file uploaded by PHP. To upload a file in php, you must first ensure that the server does not close the temporary file and write permission on the folder. the max_execution_time variable max_execution_time sets the time for PHP to wait for the script to be executed before force termination, this 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 adding the value of this variable to avoid PHP closing the script when the script is executing an important process.

The default value is max_execution_time = 90 2: file_uploads = On 3: upload_max_filesize = 2 M 4: post_max_size. a variable related to form submission is post_max_size, it controls the maximum amount of data that PHP can receive in a form submission using the POST method. You may need to increase the default value of 8 MB. Instead, it should be appropriately reduced to a more practical value.

If you want to use the php file upload function, you need to change this value to a value greater than upload_max_filesize. For example: post_max_size = 8 M 5: max_input_time this variable can be used to limit the time when data is received through POST, GET, and PUT in seconds. If the application's running environment is on a low-speed link, you need to add this value to adapt to the more time required to receive data. For example, max_input_time = 90 6: memory_limitmemory_limit = 8 M. to 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 variable memory_limit that can be used by a single script program. The value of memory_limit should be greater than the value of post_max_size.

To upload large files in php, you can refer to the following settings: open php. ini, first find

File_uploads = on; whether to allow file upload over HTTP. The default value is ON, which is to open upload_tmp_dir. the file is uploaded to the place where the temporary file is stored ON the server. if it is not specified, the system uses the default temporary folder upload_max_filesize = 8 m. Wangwen business, that is, the maximum file size that can be uploaded. The default value is 2Mpost_max_size = 8 m. It refers to the maximum value received by the form POST to PHP, including all values in the form. The default value is 8 MB.

Generally, after the preceding four parameters are set, uploading the file <= 8 m is not a problem, but the network is normal. However, if you want to upload a large file larger than 8 MB, you can only set the above four items. The following parameters must be modified unless the network has a high upload speed of 100 MB/s:

Max_execution_time = 600; maximum time (in seconds) for running each PHP page. the default value is 30 seconds. max_input_time = 600. The maximum time required for receiving data on each PHP page, the default value is 60 seconds for memory_limit = 8 m. The maximum memory consumed by each PHP page is 8 M by default.

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.