PHP large File Upload problem resolution PHP large File upload configuration reference

Source: Internet
Author: User
Tags form post php file upload php programming script php
When uploading large files in PHP programming, it always fails because PHP has a size limit for file uploads, and here is a way to share the solution for your reference.

PHP upload files related to the parameters: 0: File Upload files in the temporary directory. 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. PHP upload files, first, you need to ensure that the server does not close the temporary files, as well as write permissions to the folder 1:max_execution_time variable max_execution_time set the time before the forced termination of the script PHP waiting for the script to complete, this time 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 cases, you must consider increasing the value of this variable to prevent PHP from closing the script when the script is performing some important procedure.

The default value is: Max_execution_time = 2:file_uploads = on 3:upload_max_filesize = 2M 4:post_max_size A variable associated with the form submission is post_max_size, It will control the maximum amount of data that PHP can receive in a single form submission using the Post method. You may 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. For example: 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. For example: Max_input_time = 6:memory_limitmemory_limit = 8M To avoid running scripts that use the system's available memory heavily, PHP allows you to define memory usage limits. Use the Memory_limit variable to specify a maximum memory capacity variable that can be used by a single script memory_limit value should be appropriate greater than post_max_size value

In PHP for large file upload, you can refer to the following settings: 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 2mpost_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 the network really 100m/s upload high-speed, otherwise modify 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 each PHP page takes to receive data, default 60 seconds Memory_limit = 8m; Maximum memory consumed per PHP page, default 8M
  • 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.