The Symptom
You hit "Submit" on a large file upload, but the page reloads with no data, or your application behaves as if the form was empty. If you check your server logs, you'll see this specific warning:
Warning: POST Content-Length exceeds the limit. upload_max_filesize directive in php.ini in Unknown on line 0
This error is particularly confusing because PHP doesn't just block the file; it often wipes the entire $_POST and $_FILES arrays. Your script gets absolutely nothing to work with.
Why This Happens
PHP defaults are often quite restrictive. By default, upload_max_filesize is usually set to 2MB, and post_max_size is set to 8MB. These limits exist to protect your server's resources from being overwhelmed by massive, unexpected file uploads.
The warning triggers when the total size of your data (the Content-Length) is larger than the value defined in post_max_size. Even if you're only uploading one file, the entire request—including text fields and form metadata—must fit within these limits.
Step-by-Step Fix
1. Locate your php.ini file
Tracking down the right configuration file is the first hurdle. Since many systems have multiple PHP versions installed, the CLI might use a different php.ini than your web server. The fastest way to find the web server's path is to create a temporary info.php file in your web root:
<?php phpinfo(); ?>
Visit this file in your browser and search for Loaded Configuration File. Common paths include /etc/php/8.2/fpm/php.ini or /etc/php.ini.
2. Update the Configuration
Open that file with an editor like nano or vim. Search for and increase these three values to something more suitable for your needs—for example, to allow 100MB uploads:
; Example: Setting limits to 100 Megabytes
upload_max_filesize = 100M
post_max_size = 110M
memory_limit = 256M
A key requirement: Always ensure post_max_size is slightly larger than upload_max_filesize to account for form data overhead. Additionally, your memory_limit must be larger than post_max_size for the request to process correctly.
3. Restart your Web Server or PHP Service
PHP doesn't reload its configuration automatically. You must manually restart the service handling your PHP requests.
For Apache on Ubuntu/Debian:
sudo systemctl restart apache2
For Nginx with PHP-FPM (adjust the version as needed):
sudo systemctl restart php8.2-fpm
If you're using XAMPP or WAMP on Windows, simply use the control panel to stop and start the services.
Alternative: Fix via .htaccess (Apache only)
On shared hosting where you can't touch php.ini, you can often override these settings using an .htaccess file in your project's root directory:
php_value upload_max_filesize 100M
php_value post_max_size 110M
php_value memory_limit 256M
Note: This only works if your host has enabled AllowOverride Options for your directory.
Alternative: Fix via .user.ini (CGI/FastCGI)
For modern shared hosting running PHP as FastCGI, you can create a .user.ini file in your root folder. It's simpler than .htaccess:
upload_max_filesize = 100M
post_max_size = 110M
Important Tip for Nginx Users
Even if you fix PHP, Nginx has its own internal upload limit called client_max_body_size. If your file is still failing with a "413 Request Entity Too Large" error, you need to update your Nginx configuration (usually in /etc/nginx/nginx.conf or your site-specific config):
http {
...
client_max_body_size 100M;
}
After changing the Nginx config, run nginx -t to check for syntax errors and reload with systemctl reload nginx.

