Home >Backend Development >PHP Problem >How to set file size limit in php
The way to set the file size limit in php is: first modify [max_execution_time = 0]; then modify [post_max_size = 150M]; and finally modify [upload_max_filesize = 100M].
The operating environment of this article: windows10 system, php 7.3, thinkpad t480 computer.
When we upload a file, it may take a long time for a small file to be uploaded, but the default maximum execution time in PHP is 30 seconds, which means that if it exceeds 30 seconds, the script will stop executing. This results in the inability to open the web page.
So how do we solve this problem?
Look in php.ini
max_execution_time
The default is 30 seconds and changed to
max_execution_time = 0
0 means no limit
Modify post_max_size to set POST data The maximum size allowed. This setting also affects file uploads.
php default post_max_size is 2M. If the POST data size is greater than post_max_size $_POST and $_FILES superglobals will be empty
Find
post_max_size
Change For
post_max_size = 150M
Many people will change the second step. But when uploading files, the maximum is still 8M. Why? We also need to change a parameter upload_max_filesize to indicate the maximum size of the uploaded file.
Find upload_max_filesize, the default is 8M
Change to
upload_max_filesize = 100M
In addition, it should be noted that post_max_size is better than upload_max_filesize.
Related video tutorial sharing: php video tutorial
The above is the detailed content of How to set file size limit in php. For more information, please follow other related articles on the PHP Chinese website!