In PHP + Apache file upload operation, need to know how to control the upload file size Settings, and file size is restricted by a variety of factors, now summarized as follows:
1. Php.ini configuration
-
Upload_max_filesize Specifies the maximum size of a file to be uploaded. The default value is 2M.
-
Memory_limit This directive sets the maximum number of memory bytes that a script can request. The default value is 8M. If you don’t need any memory limits, you must set it to -1. Fatal error: Allowed memory size of X bytes exhausted (tried to allocate Y bytes) Fatal error: Allowed memory size of X bytes exhausted (tried to allocate Y bytes)
When you import a database, if the database is too large, you will get an error, so you can change this
- Post_max_size Sets the maximum size allowed for POST request data. This setting also affects file uploads. To upload large files, this value must be greater than
upload_max_filesize
. - max_execution_time = 30 ; Maximum execution time of each script, in seconds
- max_input_time = 60 ; Maximum amount of time each script may spend parsing request data
Ini :max_allowed_packet=xxM if mysql BLOB is used for binary file storage, set my.ini:max_allowed_packet=xxM
2. Configure http.conf
An option in Apache is LimitRequestBody, which limits the content of HTTP requests sent by users. This option can be used in.htaccess or httpd.conf, or in httpd.conf for virtualHost or directory properties, respectively.
The LimitRequestBody set value is between 0 (unlimited) and 2147483647 (2GB).
For example, to set the upload limit to 100K, add the following statement to.htaccess or httpd.conf:
LimitRequestBody 1024000000
Options FollowSymLinks MultiViews ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Copy the code
The Apache server receives a request with no more than LimitRequestBody bytes from the client and sends it to the PHP module, which decides whether to save it as a temporary file, sets the $_FILES global variable, and passes it to Script for further processing.
3. HTTP protocol
HTML itself can post data with a limit of 2 gigabytes.
FTP clients have a 2GB boundary limit for file offset Pointers. FTP servers or clients compiled without flag do not support files larger than 2GB in any FS.