/config/php/upload-max-filesize
php.ini upload_max_filesize and post_max_size: increase the upload limit
The commands on this page have not been executed by our verification runner yet.updated
- tool
- PHP
- file
- php.ini
- key
- upload_max_filesize
- type
- size (bytes, or with K, M, G suffix)
- default
- 2M (post_max_size 8M)
upload_max_filesize in php.ini sets the largest file PHP accepts in one upload field; the default is 2M. To allow bigger uploads, raise it and post_max_size (the limit for the whole request body, default 8M), which must be at least as large, then restart PHP-FPM or the web server. Both use sizes such as 64M or 1G.
Set the limits
upload_max_filesize = 64M
post_max_size = 72M ; >= upload_max_filesize, plus room for other fields and multiple files
max_file_uploads = 20 ; files per request (default 20)
memory_limit = 128M ; uploads are written to a temp file, not held in memoryBoth directives are PHP_INI_PERDIR: they can be set in php.ini, .user.ini (PHP-FPM and CGI), or .htaccess with php_value (Apache mod_php), but not with ini_set() at run time, because the request body is already read when the script starts.
php --ini # which php.ini the CLI uses
php -i | grep -E 'upload_max_filesize|post_max_size'
sudo systemctl restart php8.3-fpm # FPM service name depends on distro and versionThe web server's PHP can load a different php.ini than the CLI: check with phpinfo() in a page, under "Loaded Configuration File".
What happens when a limit is hit
| Limit exceeded | Symptom |
|---|---|
| upload_max_filesize | $_FILES['f']['error'] is UPLOAD_ERR_INI_SIZE (1); the other fields arrive |
| post_max_size | $_POST and $_FILES are empty; PHP logs a "POST Content-Length ... exceeds the limit" warning |
| MAX_FILE_SIZE form field | $_FILES['f']['error'] is UPLOAD_ERR_FORM_SIZE (2) |
| Web server body limit | The server answers 413 before PHP runs (nginx client_max_body_size, default 1m) |
Sources
Related pages
errors · phpPHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate N bytes)PHP hit memory_limit: 134217728 bytes is the 128M default. Process data in chunks or generators, or raise memory_limit in php.ini, with ini_set or with -d.errors · phpPHP Warning: Undefined array key "name"PHP 8 warns Undefined array key when code reads a missing key, such as an absent form field. Use ?? for a default, or isset or array_key_exists before reading.config · nginxnginx client_max_body_size: fix 413 Request Entity Too Largenginx returns 413 Request Entity Too Large when a request body exceeds client_max_body_size, 1m by default. Raise it in the server or location used for uploads.