POST Content-Length exceeds the limit
When you see an error log entry like POST Content-Length of 11933650 bytes exceeds the limit of 8388608 bytes, it is a hard boundary check in Apache/Nginx or PHP refusing to process the request. The specific value 8388608 translates exactly to 8MB. This mismatch between your expected file size (around 1GB) and the configured limit causes the upload to fail before PHP even gets a chance to handle the data stream.
To resolve this, you must adjust three distinct configuration limits in your environment. They are often conflated, but changing one without the others will result in silent failures or partial uploads.
Adjusting php.ini Settings
The error message explicitly points to the server-side limit. In a custom php.ini file located in public_html, you need to increase both upload_max_filesize and post_max_size.
Your proposed configuration sets these values to 1000M:
upload_max_filesize = 1000M ; Allows individual files up to 1GB
post_max_size = 1000M ; Ensures the entire POST body can reach 1GB
This is the correct approach. However, setting upload_max_filesize alone is insufficient. If post_max_size remains at its default (often 8MB), PHP will truncate the request or throw a warning because the total size of the POST data (which includes form fields and the file) exceeds post_max_size. Both values must be set to a value greater than your target file size, ideally equal for consistency.
You should avoid setting these arbitrarily high without reason. A 1GB limit works for large datasets, but it consumes more memory and allows attackers to send massive payloads if they bypass frontend validation. A practical upper bound is often 2GB or 4GB depending on server RAM, but 1000M is perfectly safe for a 1GB upload requirement.
The Hidden Constraint: memory_limit
You asked what to set the memory_limit to. This parameter controls how much memory PHP can use for a specific script execution, not the network buffer size.
If you are uploading a binary file (like an image or archive), you generally do not need to increase memory_limit unless you intend to process that file entirely into memory immediately after upload. For example, if your code reads the whole file with file_get_contents() or loads a massive spreadsheet into an array, you might hit the limit.
For standard uploads where you stream the data or use temporary storage:
- Default setting (128MB) is usually fine for processing logic.
- If you must load large files into memory, set it to
512Mor1G.
Crucial distinction: Increasing memory_limit does not solve the "Content-Length exceeds limit" error. That error happens at the HTTP layer (Apache/Nginx) or the PHP parsing layer before memory allocation occurs. Only changing upload_max_filesize and post_max_size fixes that specific error log message.
Client-Side Validation vs. Server Configuration
Your script snippet checks if the file is less than 1GB:
if ($_FILES["uploadedfile"]["size"] < 1000000) {
// Logic here
}
This logic contains a critical unit error. 1000000 bytes is approximately 1 megabyte, not 1 gigabyte. A gigabyte is roughly 1,073,741,824 bytes (or simply 1GB in string form if your PHP version supports it).
To correctly check for a maximum of 1GB:
// Correct comparison for 1GB (1 billion bytes)
$maxSize = 1073741824;
if ($_FILES["uploadedfile"]["size"] > $maxSize) {
return false; // Reject oversized files immediately
}
Relying solely on $_FILES["size"] is risky if the server configuration hasn't been updated yet. If upload_max_filesize is still 8MB, a malicious user could potentially exploit race conditions or buffer overflows before PHP calculates the size, though modern servers prevent this by rejecting the connection entirely.
Best Practice: Always enforce validation on three layers:
- HTML Form: Use the
max-file-sizeattribute (if supported) to warn users immediately. - PHP Logic: Check
$_FILES["size"]against a strict constant (e.g.,1GB) and reject with a clear error message if exceeded. Do not rely on the server limit alone, as it allows uploads up to 1GB but nothing larger, which might be acceptable, or it might allow slightly less due to overhead. - Server Config: Ensure
upload_max_filesizeis set higher than your maximum allowed file size (e.g., if you allow 1GB, set the limit to 2GB).
Implementation Checklist
Before restarting Apache or PHP-FPM, verify these steps:
- Edit the custom
php.ini. - Set
upload_max_filesize = 1000M. - Set
post_max_size = 1000M. - Restart the web server to apply changes.
- Update your PHP script to check against
1GB(approx1073741824) rather than1000000.
By aligning your server limits with your business logic and fixing the unit conversion in your validation code, you eliminate the "Content-Length exceeds limit" error while maintaining a secure upload pipeline.
