dev3 ·
My upload form works with small images but a 6 MB PDF returns an empty $_FILES and $_POST. I changed upload_max_filesize in php.ini but nothing changed. What settings control this?
0
DEV3 Developer Forum
Every post is reviewed first. Usually reviewed within 24 hours.
My upload form works with small images but a 6 MB PDF returns an empty $_FILES and $_POST. I changed upload_max_filesize in php.ini but nothing changed. What settings control this?
Several limits apply together. The smallest one wins.
PHP settings
| Setting | Meaning | Default |
|---|---|---|
upload_max_filesize |
max size of one file | 2M |
post_max_size |
max size of the whole request body | 8M |
max_file_uploads |
max files per request | 20 |
memory_limit |
only matters if you process the file in memory | 128M |
max_execution_time, max_input_time |
slow uploads on weak connections | 30 / 60 |
post_max_size must be larger than upload_max_filesize. If the request exceeds post_max_size, PHP drops everything, so both $_FILES and $_POST come back empty. That is the symptom you see.
Where to change it
php -i | grep "Loaded Configuration" for CLI, but for the web use phpinfo() or php_ini_loaded_file() in a script served by the web server (PHP-FPM and CLI often use different ini files).php.ini, restart PHP-FPM or Apache..user.ini file in the web root (PHP-FPM/CGI), or php_value upload_max_filesize 20M in .htaccess (only mod_php). Wrong directives in .htaccess under FPM cause a 500 error.upload_max_filesize = 20M
post_max_size = 25M
Web server limits
client_max_body_size 25m; (default 1m returns 413).LimitRequestBody.Check the error in code
if ($_FILES['doc']['error'] !== UPLOAD_ERR_OK) {
// UPLOAD_ERR_INI_SIZE (1) exceeded upload_max_filesize
// UPLOAD_ERR_FORM_SIZE (2) exceeded MAX_FILE_SIZE field
}
Verify the active values at runtime with ini_get('upload_max_filesize'). See also the .htaccess generator and nginx config generator.