Free auditStart free
GuideError · HTTP status codes

413 Payload Too Large in PHP uploads

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.

3 min
read
10
sources
Nov 1, 2026
updated
Scaplet Editorial Team
author
The short answer

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.

  1. Three limits, three different failures
  2. Find out which limit you hit
  3. Raise the limits in the right order
  4. Crawlers and uploads
30-second check

Where does your site stand?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?
Summarize this page withChatGPTClaudePerplexityGoogleAI Mode
02Check it

Find out which limit you hit

upload.php: show PHP's side of the failure
<?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');
Send a 5 MB body and read the status
# 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)
03How it works

Raise the limits in the right order

  1. 1

    Web server first

    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.

  2. 2

    Then post_max_size

    It must exceed upload_max_filesize, and PHP's docs say memory_limit should generally be larger than post_max_size.

  3. 3

    Then upload_max_filesize

    One file's cap. Both PHP settings are PHP_INI_PERDIR, so ini_set() in a script cannot change them.

  4. 4

    Restart or wait for the cache, then retest

    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.

nginx
# http, server or location context
client_max_body_size 64m;
Apache (and PHP as an Apache module, in .htaccess)
# 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
php.ini, or .user.ini for PHP-FPM and CGI
; post_max_size must be larger than upload_max_filesize
upload_max_filesize = 32M
post_max_size = 64M
memory_limit = 128M
04Explained

Crawlers and uploads

Crawlers send GET requests without a body, so these limits do not affect indexing of normal pages. A 413 on a page Google fetches is a 4xx, and Google's docs say all 4xx codes except 429 are treated as the content not existing. If a public form URL returns 413 to GET, check for an over-tight proxy limit or a misrouted rule. See 4xx errors.
Sources · 10

Every fact, linked and dated.

Official docs first. The date is when we last opened each page.
  • php.net
  • nginx.org
  • apache.org
  • github.com
  • google.com
  1. 01PHP manual: Description of core php.ini directives (post_max_size)php.net · checked 2026-11-01
  2. 02PHP manual: File uploads, configuration (upload_max_filesize, max_file_uploads)php.net · checked 2026-11-01
  3. 03PHP manual: Explanation of error messages (UPLOAD_ERR_INI_SIZE)php.net · checked 2026-11-01
  4. 04PHP manual: .user.ini filesphp.net · checked 2026-11-01
  5. 05PHP manual: Where a configuration setting may be setphp.net · checked 2026-11-01
  6. 06PHP manual: How to change configuration settings (php_value)php.net · checked 2026-11-01
  7. 07nginx: ngx_http_core_module, client_max_body_sizenginx.org · checked 2026-11-01
  8. 08Apache httpd 2.4: core features, LimitRequestBodyhttpd.apache.org · checked 2026-11-01
  9. 09Apache httpd 2.4 source: modules/http/http_filters.cgithub.com · checked 2026-11-01
  10. 10How HTTP status codes affect Google's crawlersdevelopers.google.com · checked 2026-11-01
Questions

Asked a lot.

4 questions people ask next, answered from the sources on this page.

01Why does PHP not return a 413 itself?

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.

02Which should be bigger, post_max_size or upload_max_filesize?

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.

03Can I use ini_set to raise upload_max_filesize?

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.

04Why did my change not apply?

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.

Free · 2 minutes

Tools point. Agencies advise. This one ships.

Run the free audit, then approve the fixes. Every change can be undone.

Free, no card60 secondsNobody will call you
  • 46 fixes shipped without a ticket Brightpipe
  • 0→7 ChatGPT citations in six weeks Paylane