PHP Upload Parameters

Source: Internet
Author: User
Tags form post php file upload
PHP upload file limit involves many aspects, roughly summed up, there are several:

1. Memory_limit//Memory setting limit

2, Max_execution_time//program Execution time limit

3, Post_max_size//MAX Post data limit

4, upload_max_filesize//MAX upload file size limit

Of course, these are not the absolute limit of the upload file size, theoretically only limit the maximum possible upload file size, because the memory settings are also limited to the current number of available memory, the program execution time is limited to the current system busy state, post data size is also limited to post redundant header or multi-stop upload number, etc., These factors will affect the upload file results at some point in time.

So from the logical order: memory_limit > Post_max_size > Upload_max_filesize, plus a premise Max_execution_time license time is long enough.

To summarize, assuming that the upload limit is 100M bytes, the reference settings are as follows:

; Maximum execution time of each script, in secondsmax_execution_time = 30; Maximum amount of time each script may spend parsing request Datamax_input_time = 60; Maximum input variable nesting level;max_input_nesting_level = 64; Maximum amount of memory a script may consume (128MB) memory_limit = 128M; Maximum size of POST data that PHP would accept.post_max_size = 105M; Maximum allowed size for uploaded files.upload_max_filesize = 100M

In general, when uploading a file, you first need to ensure that you upload memory, view php.ini default configuration, memory_limit default is 128M, the amount of memory that can be consumed in a script. If the upload limit is 100M, then this large amount of memory is sufficient (or generally, for example, multi-file upload may not be enough).

Adjust Set_time_limit

Max_execution_time default setting is 30 seconds, for uploading 100M files, the current network situation, 30 seconds to upload 100M files is almost impossible, 10M bandwidth completely symmetric rate, a second a trillion also need 1.5. So this setting makes it difficult to estimate the actual execution time even if it is adjusted, and the adjustment is too long to be unfriendly to Apache.

It is recommended that you do not adjust the max_execution_time, but only in the PHP program:

Set_time_limit (0);

Make temporary adjustments. Setting 0 means there is no time limit. Of course, from the point of view of program execution, set 0 is to solve the timeout problem, but in fact is not a good solution, if the program supports the continuation of the breakpoint, then set 600 seconds or 3,600 seconds also seems to be a better idea, time-out automatic breakpoint continued to pass.

Find post_max_size = 2M (default 2M) change to desired size, e.g. Post_max_size = 100M

Upload_max_filesize represents the maximum value of the uploaded file.
Find Upload_max_filesize, default is 8M to Upload_max_filesize = 100M
It is important to note that the post_max_size is greater than the Upload_max_filesize setting as well.


Finally, after the setup is complete, you need to restart Apache.
See the (php.ini Core configuration option description in the PHP manual for details)
Upload_max_filesize the maximum size of the uploaded file.
Post_max_size sets the maximum size allowed for POST data.
Memory_limit sets the maximum number of bytes of memory that a script can request.


PHP upload file related parameters php default upload limit is maximum 2M, want to upload more than this set of files, you need to adjust PHP, Apache and other parameters. Let's briefly introduce some of the parameters that are involved in PHP file uploads:
File_ Uploads
whether to allow the switch to upload files over HTTP, the default is on is open
Upload_tmp_dir
Upload_tmp_dir used to describe the PHP uploaded files placed in a temporary directory, to upload files, Ensure that the server does not close the temporary files and have write permissions to the folder, if not specified, PHP uses the system default
Upload_max_filesize
allows the maximum upload file size, default is 2M
Post_max_size
Controls the maximum amount of data that PHP can receive in a single form submission using the Post method. If you want to use PHP file upload functionality, you need to change this value to be larger than upload_max_filesize
Max_input_time
To limit the time it takes to receive data by post, get, and put in seconds. If your application is running on a low-speed link, you need to increase this value to accommodate more time to receive data
Memory_limit
to avoid running scripts that use system-wide memory, 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 appropriately greater than the value of Post_max_size
Max_execution_time
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 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


Open PHP.ini, first find
File_uploads = on; switch to allow uploading of files over HTTP. The default is on, which is open
Upload_tmp_dir; files uploaded to the server where temporary files are stored, if not specified, will use the system default temporary folder
Upload_max_filesize = 8m; Hope business, that is, the maximum size allowed to upload files. 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.

Further configure the following parameters
Max_execution_time = 600; maximum time value per php page (seconds), default 30 seconds
Max_input_time = 600; The maximum time required for each PHP page to receive data, default 60 seconds
Memory_limit = 8m; max memory consumed per PHP page, default 8M
After modifying the above parameters, it is possible to upload large volume files under normal conditions allowed by the network.
Max_execution_time = 600
Max_input_time = 600
Memory_limit = 32m
File_uploads = On
Upload_tmp_dir =/tmp
Upload_max_filesize = 32m
Post_max_size = 32m

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