# 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.

Canonical: https://scaplet.com/errors/http/413/php

Guide Error · HTTP status codes

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

413 4xx · Client error

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](#three-limits-three-different-failures)
2. [Find out which limit you hit](#find-out-which-limit-you-hit)
3. [Raise the limits in the right order](#raise-the-limits-in-the-right-order)
4. [Crawlers and uploads](#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 with [ChatGPT](https://chatgpt.com/?hints=search&q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F413%2Fphp%20(%22413%20Payload%20Too%20Large%20in%20PHP%20uploads%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Claude](https://claude.ai/new?q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F413%2Fphp%20(%22413%20Payload%20Too%20Large%20in%20PHP%20uploads%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Perplexity](https://www.perplexity.ai/search?q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F413%2Fphp%20(%22413%20Payload%20Too%20Large%20in%20PHP%20uploads%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [![Google](/logos/ai/google-color.svg)AI Mode](https://www.google.com/search?udm=50&q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F413%2Fphp%20(%22413%20Payload%20Too%20Large%20in%20PHP%20uploads%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.)

_01_Where the limit lives and what you see

## Three limits, three different failures

An upload passes through the web server, then PHP. Each layer has a size limit, and each fails differently, which tells you which one to raise. The general meaning of the status is on [413 Request Entity Too Large](/errors/http/413).

Layer

### nginx

Setting and default

`client_max_body_size`, default `1m`; `0` disables the check

What fails

nginx returns 413. The docs warn "browsers cannot correctly display this error"

Layer

### Apache

Setting and default

`LimitRequestBody`, default 1073741824 bytes (in 2.4.53 and earlier the default was 0, unlimited); `0` means unlimited

What fails

Apache returns 413 and logs `Requested content-length of N is larger than the configured limit of M` at info level, which a default `LogLevel warn` hides

Layer

### PHP: post_max_size

Setting and default

Default `"8M"`. Applies to the whole POST body and also affects file uploads

What fails

PHP does not send a 413. Over the limit, `$_POST` and `$_FILES` are empty

Layer

### PHP: upload_max_filesize

Setting and default

Default `"2M"`, one file. `post_max_size` must be larger than this value

What fails

`$_FILES['f']['error']` is `UPLOAD_ERR_INI_SIZE`: "The uploaded file exceeds the upload_max_filesize directive in php.ini"

Layer

### PHP: max_file_uploads

Setting and default

Default `20`, files per request

What fails

The maximum number of files allowed to be uploaded simultaneously

**How to tell the layers apart**A real `413` status in DevTools or `curl -i` means the web server rejected the body before PHP ran. A `200` with a PHP page that says the file is missing means PHP's own limits. Check the status line first, then the error code.

_02_Check 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)
```

_03_How 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
```

**Pick the file by how PHP runs**PHP's manual says `.user.ini` files are processed only by the CGI/FastCGI SAPI, and that if you run PHP as an Apache module you should use `.htaccess` for the same effect. Match the file to the SAPI. The values above are examples; size them to your use case.

_04_Explained

## 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](/seo-issues/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. 01 [PHP manual: Description of core php.ini directives (post_max_size)](https://www.php.net/manual/en/ini.core.php) php.net · checked 2026-11-01
2. 02 [PHP manual: File uploads, configuration (upload_max_filesize, max_file_uploads)](https://www.php.net/manual/en/ini.list.php) php.net · checked 2026-11-01
3. 03 [PHP manual: Explanation of error messages (UPLOAD_ERR_INI_SIZE)](https://www.php.net/manual/en/features.file-upload.errors.php) php.net · checked 2026-11-01
4. 04 [PHP manual: .user.ini files](https://www.php.net/manual/en/configuration.file.per-user.php) php.net · checked 2026-11-01
5. 05 [PHP manual: Where a configuration setting may be set](https://www.php.net/manual/en/configuration.changes.modes.php) php.net · checked 2026-11-01
6. 06 [PHP manual: How to change configuration settings (php_value)](https://www.php.net/manual/en/configuration.changes.php) php.net · checked 2026-11-01
7. 07 [nginx: ngx_http_core_module, client_max_body_size](https://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size) nginx.org · checked 2026-11-01
8. 08 [Apache httpd 2.4: core features, LimitRequestBody](https://httpd.apache.org/docs/2.4/mod/core.html#limitrequestbody) httpd.apache.org · checked 2026-11-01
9. 09 [Apache httpd 2.4 source: modules/http/http_filters.c](https://github.com/apache/httpd/blob/2.4.x/modules/http/http_filters.c) github.com · checked 2026-11-01
10. 10 [How HTTP status codes affect Google's crawlers](https://developers.google.com/crawling/docs/troubleshooting/http-status-codes) developers.google.com · checked 2026-11-01

Questions

## Asked a lot.

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

_01_ Why 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.

_02_ Which 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.

_03_ Can 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.

_04_ Why 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.

## Keep learning

[All errors](/errors)

[Learn 413 Request Entity Too Large in Apache HTTP status codes](/errors/http/413/apache) [Related 4xx errors Status codes and links](/seo-issues/4xx-errors) [Read next 413 Request Entity Too Large HTTP status codes](/errors/http/413) [Do Run a free site audit Free, about two minutes](/site-audit)

Other 413 errors
[413 Request Entity Too Large in nginx](/errors/http/413/nginx) [Vercel 413: FUNCTION_PAYLOAD_TOO_LARGE](/errors/cdn/vercel-payload-too-large) [413 Payload Too Large in Express](/errors/http/413/express) [413 Payload Too Large on Cloudflare](/errors/http/413/cloudflare) [413 Request Entity Too Large](/errors/http/413)

Nearby in errors
[414 URI Too Long](/errors/http/414) [415 Unsupported Media Type](/errors/http/415)

More in 413 Request Entity Too Large
[413 Payload Too Large in Express](/errors/http/413/express) [413 Payload Too Large in PHP uploads](/errors/http/413/php) [413 Payload Too Large on Cloudflare](/errors/http/413/cloudflare) [413 Request Entity Too Large in Apache](/errors/http/413/apache) [413 Request Entity Too Large in IIS](/errors/http/413/iis) [413 Request Entity Too Large in nginx](/errors/http/413/nginx)

Free · 2 minutes

## Tools point. Agencies advise. _This one ships._

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

[Audit my site free](/site-audit)

Free, no card 60 seconds Nobody will call you

- **46** fixes shipped without a ticket Brightpipe
- **0→7** ChatGPT citations in six weeks Paylane
