nginx
- Setting and default
client_max_body_size, default1m;0disables the check- What fails
- nginx returns 413. The docs warn "browsers cannot correctly display this error"
Upload failing with a 413 or an empty $_FILES in PHP? Raise client_max_body_size, LimitRequestBody, post_max_size and upload_max_filesize in order, with a test.
PHP itself does not send a 413. The 413 comes from the web server in front of it (nginx client_max_body_size, Apache LimitRequestBody). PHP has its own two limits behind that: post_max_size and upload_max_filesize, which fail quietly with an empty $_POST and $_FILES. Raise all of them, with post_max_size larger than upload_max_filesize.
Four quick questions, then a straight answer.
From your answers, this is quietly costing you traffic and nobody has the hours to chase it. Scaplet finds every affected page, drafts the fixes and tracks how AI answers mention you.
A data platform shipped 46 fixes without a ticket.
This looks handled. Re-check after a redesign, a migration or a big content push; that is when it breaks.
Your site is small and you have the time. Work through the steps on this page, starting with the pages that get the most traffic.
client_max_body_size, default 1m; 0 disables the checkLimitRequestBody, default 1073741824 bytes (in 2.4.53 and earlier the default was 0, unlimited); 0 means unlimitedRequested content-length of N is larger than the configured limit of M at info level, which a default LogLevel warn hides"8M". Applies to the whole POST body and also affects file uploads$_POST and $_FILES are empty"2M", one file. post_max_size must be larger than this value$_FILES['f']['error'] is UPLOAD_ERR_INI_SIZE: "The uploaded file exceeds the upload_max_filesize directive in php.ini"20, files per request<?php
// post_max_size exceeded: $_POST and $_FILES are both empty
if ($_SERVER['REQUEST_METHOD'] === 'POST' && empty($_POST) && empty($_FILES)
&& (int) ($_SERVER['CONTENT_LENGTH'] ?? 0) > 0) {
exit('Body is larger than post_max_size: ' . ini_get('post_max_size'));
}
if (isset($_FILES['file']) && $_FILES['file']['error'] === UPLOAD_ERR_INI_SIZE) {
exit('File is larger than upload_max_filesize: ' . ini_get('upload_max_filesize'));
}
// What PHP is running with right now
echo ini_get('upload_max_filesize'), ' / ', ini_get('post_max_size'), ' / ', ini_get('max_file_uploads');# Make a test file and post it to your upload endpoint
head -c 5000000 /dev/zero > /tmp/test.bin
curl -i -F "file=@/tmp/test.bin" https://example.com/upload.php
# 413 Request Entity Too Large -> nginx or Apache limit
# 200 and a missing-file message -> PHP limits (check below)A web server limit rejects the body before PHP sees it, so changing PHP alone does nothing. Set it a little above your biggest expected upload.
It must exceed upload_max_filesize, and PHP's docs say memory_limit should generally be larger than post_max_size.
One file's cap. Both PHP settings are PHP_INI_PERDIR, so ini_set() in a script cannot change them.
Reload PHP-FPM or Apache. For .user.ini files PHP re-reads them every user_ini.cache_ttl seconds, default 300 (5 minutes). Re-run the curl test.
# http, server or location context
client_max_body_size 64m;# 64 MB in bytes; context allows .htaccess when AllowOverride permits it
LimitRequestBody 67108864
# mod_php only: PERDIR settings can be set in .htaccess
php_value upload_max_filesize 32M
php_value post_max_size 64M; post_max_size must be larger than upload_max_filesize
upload_max_filesize = 32M
post_max_size = 64M
memory_limit = 128M4 questions people ask next, answered from the sources on this page.
PHP's limits are applied while it parses the request. Over post_max_size the superglobals $_POST and $_FILES are empty, and over upload_max_filesize the file gets error code UPLOAD_ERR_INI_SIZE. A 413 status is sent by the web server, such as nginx or Apache.
post_max_size. PHP's documentation says it must be larger than upload_max_filesize for large uploads to work, and it applies to the entire request body, including every field and file.
No. Both settings are PHP_INI_PERDIR, which can be set in php.ini, .htaccess, httpd.conf or .user.ini but not by ini_set() in a script.
Reload PHP-FPM or Apache, and remember that .user.ini is cached for user_ini.cache_ttl seconds (default 300). Also confirm the web server limit is higher, since that layer rejects first.
Run the free audit, then approve the fixes. Every change can be undone.