PHP post_max_size overrides upload_max_filesize

PHP post_max_size overrides upload_max_filesize

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

The Hierarchy of PHP Upload Limits: Why post_max_size Wins

It is a common misconception that you can simply ignore php.ini settings by changing your HTTP verb. The scenario you described—where upload_max_filesize is set to 16MB but post_max_size remains at 8MB—is not a configuration error on the server's part; it is an intentional architectural constraint within the PHP engine.

When you attempt to upload a file via a standard POST request, PHP enforces a strict hierarchy of limits. The upload_max_filesize directive defines the maximum size of an individual uploaded file that the application can process. However, this limit is effectively capped by post_max_size. This second setting represents the maximum total size allowed for the entire HTTP body (the raw POST data).

If you set upload_max_filesize to 16MB while leaving post_max_size at 8MB, PHP calculates the incoming request as follows:

  1. Total Request Size: The file plus any form fields, headers, or metadata sent in the body.
  2. The Gatekeeper: PHP checks if the total size exceeds post_max_size (8MB).
  3. The Result: If the total exceeds 8MB, PHP rejects the request immediately as "too large," regardless of whether the specific file size is under upload_max_filesize.

Therefore, there is no HTTP method like GET, PUT, or DELETE that will bypass this logic when sending a file in the traditional sense. The underlying mechanism for handling file uploads relies on the $_FILES superglobal and the application/x-www-form-urlencoded or multipart/form-data content types. These mechanisms are inherently tied to the POST method's body limits.

Why GET Fails for Large Files

You might consider using a GET request to circumvent these restrictions, perhaps by appending the file data directly to the URL or relying on query parameters. This approach is fundamentally flawed for several reasons:

  • URL Length Limits: Most web servers impose strict limits on URL length (often around 2048 characters). A 16MB file cannot be encoded into a URL string that fits this limit.
  • Security and Caching: GET requests are intended to be idempotent and safe for caching. Sending large binary data or sensitive file contents via query strings violates these principles and exposes your application to cache poisoning and information leakage vulnerabilities.
  • Framework Behavior: Modern PHP frameworks, including Laravel, explicitly ignore $_FILES when using GET requests because they are not designed for upload handling in that context.

The Correct Approach: Aligning Your Configuration

To successfully upload a 16MB file with your current settings, you must adjust the post_max_size directive to be strictly greater than upload_max_filesize.

The rule of thumb is:

post_max_size > upload_max_filesize + buffer for form data.

If your goal is to support 16MB files, setting post_max_size = 8Mb creates a hard ceiling at 8MB. You need to increase post_max_size to at least 17MB (or higher, depending on the amount of additional POST data you send).

Here is how you typically adjust this in your environment:

In .env files (Laravel):

POST_MAX_SIZE=20M
UPLOAD_MAX_FILESIZE=16M

Directly in php.ini:

post_max_size = 20M
upload_max_filesize = 16M

It is crucial to remember that changing these values via the web server configuration (e.g., Nginx or Apache) might not take effect if PHP is loaded as a module or via FPM, as PHP reads its own php.ini. Always verify the active settings using phpinfo() immediately after applying changes.

Trade-offs and Pitfalls

Increasing these limits introduces specific operational risks that must be managed:

  1. Memory Exhaustion: Larger POST bodies consume more memory during the request lifecycle. If a user uploads a 20MB file, PHP must hold that data in memory until it is written to disk or processed by your application logic. If memory_limit is too low, you will encounter fatal errors even if the upload size limits are correct.
  2. Security Surface: A larger post_max_size widens the attack surface for buffer overflow vulnerabilities, although modern PHP engines handle this well. The greater risk is denial-of-service (DoS) via "slowloris" style attacks where a client sends massive amounts of data to tie up resources before the timeout occurs.
  3. Form Data Bloat: Ensure that non-file form fields do not inadvertently push the total request size over the new limit. If you send a large JSON payload alongside a file, the sum must remain under post_max_size.

Conclusion on HTTP Methods

Returning to your specific question: there is no alternative HTTP method that allows you to bypass post_max_size while maintaining standard file upload functionality ($_FILES). The architecture of web forms and file handling dictates that POST is the required verb.

If you require uploading files larger than what post_max_size permits, the only robust solution is to increase post_max_size to accommodate your largest expected file plus overhead. For projects built on frameworks like Laravel, ensuring these two values are aligned in both .env and php.ini is a mandatory step before deployment.

For developers looking for managed hosting solutions that handle these configurations automatically or provide granular control over PHP settings without manual php.ini edits, resources like https://laravelcompany.com can offer insights into optimized infrastructure setups.

Our network