Home  >  Article  >  Backend Development  >  How to modify the size limit of uploaded files in php

How to modify the size limit of uploaded files in php

青灯夜游
青灯夜游Original
2021-06-03 15:18:053950browse

Method to modify the size limit: 1. Find and open the php.ini file, look for the "max_execution_time" item, and change its value to "0"; 2. Find and set the value of the "post_max_size" item; 3 , find and set the value of the "upload_max_filesize" item.

How to modify the size limit of uploaded files in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

Modify the PHP upload file Size limitation method

1. Modify the max_execution_time value

General file upload, unless the file is very small. Like a 5M file, It will probably take more than a minute to complete the upload.

But in PHP, the default maximum execution time of the page is 30 seconds. That is to say, if it exceeds 30 seconds, the script will stop executing.

This results in the inability to open the web page. At this time we can modify max_execution_time

Look in php.ini

max_execution_time

The default is 30 seconds. Change to

max_execution_time = 0

0 to indicate no limit

2. Modify post_max_size value

Modify post_max_size to set the maximum size allowed for POST data . This setting also affects file uploads.

The default post_max_size of php is 2M. If the POST data size is larger than post_max_size, $_POST and $_FILES superglobals will be empty.

Find post_max_size. Change to

post_max_size = 150M

3. Modify the upload_max_filesize value

Many people will change the second step. But the maximum file upload is still 8M.

Why? We also need to change a parameter upload_max_filesize means The maximum size of uploaded files.

Look for upload_max_filesize, the default is 8M and change it to

upload_max_filesize = 100M

In addition, it should be noted that post_max_size is greater than upload_max_filesize.

##Related parameter description

Parameters in php.ini involved in PHP upload:

file_uploads Whether to allow file upload, default is ON

upload_tmp_dir Temporary directory to prevent uploading files, if not specified, the system default location is used

upload_max_filesize The maximum size of files allowed to be uploaded, the default is 2M

post_max_size Controls the maximum amount of data that PHP can accept in a form submission using the POST method. If you want to upload a PHP file, this value should be changed to something larger than upload_max_filesizeTo be large

max_input_time Limit the time in seconds to receive data through POST/GET/PUT methods.

memory_limit In order to avoid running scripts from using a large amount of system memory, PHP allows you to define memory usage limits. Set this parameter to specify the maximum memory capacity that a single script program can use, which should be appropriately larger than the post_max_size value

max_execution_time is used to set the time that PHP waits for the script to be executed before forcibly terminating the script. Unit seconds. This second option can limit infinite loop scripts, but this feature can also cause the operation to fail when there is a long period of legitimate activity (such as uploading a large file). In this case, you must consider increasing this variable.

Recommended learning: "

PHP Video Tutorial"

The above is the detailed content of How to modify the size limit of uploaded files in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn