PHP Large File Upload problem analysis

Source: Internet
Author: User
Introduction of the next PHP upload large file configuration method, on some PHP upload parameters to explain how to implement a large file upload in PHP, the need for a friend reference.

PHP File upload Required parameters: A few parameter adjustment: 0: File upload when the temporary directory to store files. Must be a user-writable directory for the PHP process owner. If not specified, PHP uses the system default php.ini file in Upload_tmp_dir to describe the temporary directory where PHP uploads files are placed. To upload a file, you need to ensure that the server does not close the temporary file and has write permission to the folder

The 1:max_execution_time 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 this case, you need to consider increasing the value of this variable to avoid PHP closing the script when the script is performing some important process. Max_execution_time = 90

2:file_uploads = On

3:upload_max_filesize = 2M

4:post_max_size

One of the variables associated with form submission is post_max_size, which controls the maximum amount of data that PHP can receive in a single form submission using the Post method. It seems unlikely that you need to change the default of 8 MB to a larger size. Instead, it should be appropriately lowered to a more realistic value. However, if you want to use PHP file upload functionality, you need to change this value to be larger than upload_max_filesize. Post_max_size = 8M

5: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 on a low-speed link, you need to increase this value to accommodate the additional time it takes to receive the data. Max_input_time = 90

6:memory_limit Memory_limit = 8M

To prevent running scripts from using the system's available memory heavily, PHP allows you to define memory usage limits. Specify the maximum amount of memory that a single script can use by using the Memory_limit variable

The value of the variable memory_limit should be appropriately greater than the value of post_max_size

Implementation of PHP Large file upload, a simple configuration example:

1: Open php.ini, first find

File_uploads = on; switch to allow uploading of files over HTTP. The default is on is open Upload_tmp_dir, the file is uploaded to the server where temporary files are stored, if not specified will be used the system default temporary folder Upload_max_filesize = 8m; Wang Wen Business, that is, allow the maximum size of the upload file. The default is 2M post_max_size = 8m; The maximum value that can be received by the form Post to PHP, including all values in the form. Default is 8M

Generally, after setting the above four parameters, uploading <=8m files is not a problem, in the network normal situation.

However, if you want to upload a large volume of >8m files, only set the above four items will certainly be able to pass. Unless your network really 100m/s upload high-speed, otherwise you have to care about the following parameters

Max_execution_time = 600; The maximum time value for each PHP page to run (seconds), default 30 seconds Max_input_time = 600, the maximum time per PHP page to receive data, default 60 seconds Memory_limit = 8m, each ph Max memory eaten by P page, default 8M

After modifying the above parameters, in the normal circumstances allowed by the network, you can upload large files.

  • 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.