How to modify the size limit of PHP files to be uploaded

Source: Internet
Author: User
Tags file upload ini memory usage php file upload

Php. ini

File_uploads = on; whether to allow file upload over HTTP. ON is enabled by default.
Upload_tmp_dir; upload the file to the place where the temporary file is stored on the server. If it is not specified, the default temporary folder will be used.
Upload_max_filesize = 8 m; Wangwen business, that is, the maximum file size allowed to be uploaded. The default value is 2 MB.
Post_max_size = 8 m; the maximum value that can be received by posting a form to PHP, including all values in the form. The default value is 8 MB.

Use the. htaccess file

Write in htaccess

Php_value post_max_size 12 m

Php_value upload_max_filesize 12 m

Php_value max_execution_time 120

Php_value max_input_time 240

However, in php, the longest execution time of this page is 30 seconds by default. That is to say, the script is stopped after 30 seconds.

This causes the web page to fail to be opened. In this case, we can modify max_execution_time.

Search in php. ini


The default value is 30 seconds.

Max_execution_time = 0

0 indicates no limit

Another way is to add

Set_time_limit ();

To set the longest page execution time.

Set_time_limit (0); // 0 indicates no limit

In addition, post_max_size is better than upload_max_filesize.

Next, we will briefly introduce some parameters involved in php file upload:

· File_uploads: whether to allow file upload over HTTP. The default value is ON, that is, whether to allow upload_tmp_dir to indicate the temporary directory of files uploaded by PHP. To upload files, make sure that the server does not have the permission to close temporary files and write to folders. If not specified, PHP uses the system default value. Upload_max_filesize: maximum size of the file to be uploaded. The default value is 2Mpost_max_size, which controls the maximum data size that PHP can receive in a form submission using the POST method. If you want to use the php file upload function, you need to change this value to a value greater than upload_max_filesize.

· Max_input_time limits the time for receiving data 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.
· Memory_limit: to avoid using a large amount of available system memory for running scripts, PHP allows you to define the memory usage limit. The memory_limit variable is used to specify the maximum memory capacity variable memory_limit that a single script program can use. The value of memory_limit should be greater than the value of post_max_size.

· Max_execution_time 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 closing the script when the script is executing an important process.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.