About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.
This message appears when an uploaded file is larger than PHP's upload_max_filesize, which defaults to 2M. Raising that one value may not be the whole fix. post_max_size caps the entire request, memory_limit, time limits and the web server's own body limit also apply, and when post_max_size is the limit that trips, PHP gives no error code at all.
What the symptom means
PHP reports upload problems as error codes in $_FILES['userfile']['error']. The PHP documentation defines UPLOAD_ERR_INI_SIZE (value 1) as: "The uploaded file exceeds the upload_max_filesize directive in php.ini." The other codes tell you the problem is something else:
| Code | Constant | Meaning in the PHP documentation |
|---|---|---|
| 1 | UPLOAD_ERR_INI_SIZE |
The uploaded file exceeds the upload_max_filesize directive in php.ini |
| 2 | UPLOAD_ERR_FORM_SIZE |
The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form |
| 3 | UPLOAD_ERR_PARTIAL |
The uploaded file was only partially uploaded |
| 4 | UPLOAD_ERR_NO_FILE |
No file was uploaded |
| 6 | UPLOAD_ERR_NO_TMP_DIR |
Missing a temporary folder |
| 7 | UPLOAD_ERR_CANT_WRITE |
Failed to write file to disk |
| 8 | UPLOAD_ERR_EXTENSION |
A PHP extension stopped the file upload |
The directives involved, with the defaults and change modes the PHP manual lists, are:
upload_max_filesize: "The maximum size of an uploaded file." Default "2M", modeINI_PERDIR.post_max_size: "Sets max size of post data allowed. This setting also affects file upload." Default "8M", modeINI_PERDIR. The manual adds: "To upload large files, this value must be larger than upload_max_filesize."max_file_uploads: the maximum number of files per request, default 20.memory_limit: "Generally speaking, memory_limit should be larger than post_max_size."max_input_timeandmax_execution_time: input time includes the upload. The directive list showsmax_input_timeas "-1", which the manual explains meansmax_execution_timeis used instead, andmax_execution_timeas "30" seconds.upload_tmp_dir: where PHP stores the file while it handles it; it "Must be writable by whatever user PHP is running as".
The trap is this sentence from the manual: "If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty." The file vanishes with no error code, so a form handler may report that no file was selected instead.
INI_PERDIR means the value can be set in php.ini, .htaccess, httpd.conf or .user.ini. The manual's example of an INI_PERDIR setting says it "may not be set using ini_set()".
Likely causes
| Cause | What you see | How to confirm |
|---|---|---|
File larger than upload_max_filesize |
Error code 1 and the message above | Compare the file size with the effective value |
Request larger than post_max_size |
$_FILES and $_POST empty, no error code |
The effective post_max_size is smaller than the upload |
| Web server body limit lower than PHP's | A 413 response from the web server, PHP never runs | The web server's error log; for nginx, see "nginx 413 Request Entity Too Large: client_max_body_size and the limits behind it" |
Edited the wrong php.ini |
Values on the website do not change | ini_get on the web path shows the old value |
| Time or memory limit hit on slow or large uploads | The upload stops part way, or a memory error follows | max_input_time, max_execution_time, memory_limit and the PHP error log |
| Temporary folder missing or not writable | Error code 6 or 7 | upload_tmp_dir or the system default is missing or has no free space |
Prove the cause before changing anything
1. Get the error code. If the application shows the message above, the code is 1. If it says no file was uploaded, suspect post_max_size. For a custom form, read $_FILES['userfile']['error'].
2. Read the effective values for the web path. The command-line php can load a different file from FPM.
Risk: a temporary script in the document root is reachable and discloses server details, so you will request it once, then show it and remove only that file.
Put a short temporary script in the document root, with a long random name of your own (for example limits-k8d2x7q9.php):
<?php
foreach (['upload_max_filesize', 'post_max_size', 'memory_limit', 'max_input_time', 'max_execution_time', 'max_file_uploads', 'upload_tmp_dir'] as $k) {
echo $k, '=', var_export(ini_get($k), true), "\n";
}
echo php_ini_loaded_file(), "\n";
Request it through the web server. ini_get returns the configuration value in force for that request. A .user.ini is read per directory, so put the test script in the same directory as the upload script. php_ini_loaded_file() prints the path of the php.ini that was loaded.
Once you have requested it, show the exact file and remove only that file, using your own random name:
ls -l /var/www/app/public/limits-k8d2x7q9.php
rm /var/www/app/public/limits-k8d2x7q9.php
There is nothing to restore for this step.
3. Check the web server first for a 413. A 413 means the web server stopped the request before PHP saw it. "nginx 413 Request Entity Too Large: client_max_body_size and the limits behind it" covers that layer.
4. Compare sizes. Show the arithmetic: M means 1,048,576 bytes. A 12M file is 12 × 1,048,576 = 12,582,912 bytes, and the form adds a little more to the request.
Fix
Choose the target first. To allow files up to 64M, set upload_max_filesize to 64M (67,108,864 bytes). Set post_max_size above it: 72M (75,497,472 bytes) leaves 8M of headroom for form fields and other parts of the request, a choice you can adjust. Check that memory_limit is larger than post_max_size; the default 128M (134,217,728 bytes) is. Raise the web server's own limit to at least the request size. For nginx, follow "nginx 413 Request Entity Too Large: client_max_body_size and the limits behind it", including its save-first copy, nginx -t, reload and back-out steps, before you change that limit.
Where to put the values depends on how PHP runs:
php.ini: edit the filephp_ini_loaded_file()reported.- An FPM pool: the manual shows pool syntax such as
php_admin_value[memory_limit] = 32M, andphp_admin_value[upload_max_filesize] = 64Mandphp_admin_value[post_max_size] = 72Mfollow that pattern (the manual shows no pool example for these two directives). Values set withphp_admin_value"cannot be overridden with ini_set()". .user.ini: PHP scans for it in each directory, but only for CGI and FastCGI, anduser_ini.cache_ttl"controls how often user INI files are re-read. The default is 300 seconds (5 minutes)." A change can take that long to show.
Risk: if you put the values in a .user.ini, a bad line in it affects every script in that directory, and the PHP manual describes no command that tests a .user.ini before use. Check the result as in "Confirm the fix" below. Before you edit it, copy it with a dated name (for example cp -p .user.ini /root/user.ini.2026-11-20), or, if the file does not exist yet, note that you will delete the new file to back out. To back out, copy the saved file back as .user.ini (or delete the new one) and allow up to user_ini.cache_ttl for PHP to read it again.
For php.ini or a pool file, save the file and test the configuration. If you edit a pool file instead, save that file the same way, with a dated copy, and use its name in the back-out. For a php.ini at /etc/php/8.4/fpm/php.ini:
cp -p /etc/php/8.4/fpm/php.ini /etc/php/8.4/fpm/php.ini.2026-11-20
php-fpm -t
Disruptive step: reloading FPM with the systemctl reload command below asks the service to read its configuration again. The PHP manual does not describe what happens to requests in flight during a reload, so reload in a quiet period, when no large upload is running.
The PHP source describes the option as "-t, --test Test FPM configuration and exit". Use the php-fpm binary your system installs. Edit the three values, run php-fpm -t again, then reload:
systemctl reload php8.4-fpm
To back out, restore the copy under the name you saved, test, and reload again:
cp -p /etc/php/8.4/fpm/php.ini.2026-11-20 /etc/php/8.4/fpm/php.ini
php-fpm -t
systemctl reload php8.4-fpm
If you raised max_input_time or max_execution_time for slow connections, the manual warns that max_execution_time does not count the "time taken by the file upload process", while max_input_time "sets the maximum time, in seconds, the script is allowed to receive input; this includes file uploads". Raise only the value that matches the failure.
Example (illustrative): On web01, an editor cannot upload a 5M image to app.example.com: "The uploaded file exceeds the upload_max_filesize directive in php.ini". The limits script reports upload_max_filesize='2M' (2,097,152 bytes). The administrator raises it to 16M (16,777,216 bytes) only. A 12M file now fails differently: no size message, and the form says no file was selected, because post_max_size is still 8M (8,388,608 bytes) and 12 × 1,048,576 = 12,582,912 is larger. Setting post_max_size to 24M (25,165,824 bytes), and checking that the nginx body limit allows it, fixes it.
Confirm the fix
- Put the limits script from step 2 back under a new random name (the Risk in step 2 applies again), request it once, see the new values, then remove it.
- Upload a file just under the new
upload_max_filesize. It completes, and the file appears. - Upload a file just over it. You get the message for error code 1, which proves the new limit is the one in force.
- Check the web server and PHP error logs for new lines during these tests.
- If the test file is large, watch the memory use and duration of the request so the limits above hold under real load.
What to watch afterwards
- Record the three values and the web server limit together, so a change to one prompts a check of the others.
- After a PHP upgrade or package update, read the effective values again. A new
php.inican undo your edit. - Watch the temporary directory's free space during heavy upload periods.
- If many large uploads run at once, recheck the memory budget for FPM workers: see "PHP-FPM Has Reached pm.max_children: Measure Queueing Before Adding Workers".
Read next
Related articles you may want next.
- Troubleshootingnginx 413 Request Entity Too Large: client_max_body_size and the limits behind itnginx 413 Request Entity Too Large on uploads: the default client_max_body_size is 1m. Read the error log, raise it per location and match PHP limits.Read article
- PerformancePHP-FPM Has Reached pm.max_children: Measure Queueing Before Adding WorkersSeparate long-running requests from insufficient concurrency and size workers against measured memory and dependency limits.Read article
- TroubleshootingPHP "Allowed memory size of ... bytes exhausted": raise memory_limit only after finding the causePHP 'Allowed memory size of N bytes exhausted': find the memory_limit that applies to PHP-FPM, find the cause, then raise it safely or fix the code.Read article
Risks and limits
- These commands have not been run or lab-tested.
- The manual pages disagree about one default. The directive list shows
max_input_timeas "-1", while the upload pitfalls page says "the default of 60 seconds may be exceeded". Read your effective value withini_getrather than relying on either figure. - Very large uploads through a normal form are fragile on slow links, whatever the limits. No advice on chunked or resumable uploads is given here.
- Proxies and CDNs in front of the web server can have their own body limits. They are not covered.
- Unit names,
php.inipaths and thephp-fpmbinary name differ between systems. Use the paths your own checks reported.
Sources
- PHP manual: Description of core php.ini directives — PHP documentation, no date shown, accessed 20 November 2026
- PHP manual: Runtime configuration (max_execution_time, max_input_time) — PHP documentation, no date shown, accessed 20 November 2026
- PHP manual: Common Pitfalls (file uploads) — PHP documentation, no date shown, accessed 20 November 2026
- PHP manual: Error Messages Explained — PHP documentation, no date shown, accessed 20 November 2026
- PHP documentation source: reference/filesystem/constants.xml — PHP documentation project, master branch, no date shown, accessed 20 November 2026
- PHP manual: .user.ini files — PHP documentation, no date shown, accessed 20 November 2026
- PHP manual: Where a configuration setting may be set — PHP documentation, no date shown, accessed 20 November 2026
- PHP manual: FastCGI Process Manager configuration — PHP documentation, no date shown, accessed 20 November 2026
- PHP manual: ini_get — PHP documentation, no date shown, accessed 20 November 2026
- php-src PHP-8.4: sapi/fpm/fpm/fpm_main.c — PHP project source, branch PHP-8.4, no date shown, accessed 20 November 2026
This article was originally published on .