The php setting allows large file uploads of sample code

  • 2021-01-22 04:55:06
  • OfStack

Use Nginx as proxy server with apache2 as backend. Set to allow uploading of files up to 100M.

1. Nginx configuration:

http {
......
client_max_body_size 100m;
......
}

2. PHP configuration file
......
; Maximum execution time of each script, in seconds
; http://php.net/max-execution-time
; Note: This directive is hardcoded to 0 for the CLI SAPI
max_execution_time = 0

......
[Data Handling]
; Maximum size of POST data that PHP will accept.
; http://php.net/post-max-size
post_max_size = 100M

......
[File Uploads]
; Maximum allowed size for uploaded files
upload_max_filesize = 100M

......

$_FILES[file]['error'] $_FILES[file]['error'

UPLOAD_ERR_OK
The value is 0, no error occurred, and the file was uploaded successfully.

UPLOAD_ERR_INI_SIZE
With a value of 1, the uploaded file exceeds the limit of the upload_max_filesize option in php.ini.

UPLOAD_ERR_FORM_SIZE
With a value of 2, the size of the uploaded file exceeds the value specified by the option MAX_FILE_SIZE in the HTML form.

UPLOAD_ERR_PARTIAL
With a value of 3, only part of the file is uploaded.

UPLOAD_ERR_NO_FILE
The value is 4 and no files have been uploaded.

UPLOAD_ERR_NO_TMP_DIR
The value is 6. The temporary folder cannot be found. PHP 4.3.10 and PHP 5.0.3 were introduced.

UPLOAD_ERR_CANT_WRITE
The value is 7. File write failed. PHP 5.1.0 was introduced.

Related articles: