- How to Fix the POST Content-Length Exceeded Error
- What Does the Error Mean?
- How Can I Increase the Maximum Upload Limit in WordPress?
- Solution #1: Using the AwardSpace PHP Settings Manager
- Solution #2: Generating a custom php.ini file
- Fix: POST Content-Length of X bytes exceeds the limit of X bytes.
- What is my post_max_size setting?
- How to increase your post_max_size setting.
- Can I use the ini_set function to change the post_max_size directive?
- PHP Warning: POST Content-Length of 8978294 bytes exceeds the limit…
- Step 1: Locate your PHP configuration file
- Step 2: Edit the post_max_size directive
- Step 3: Edit the upload_max_filesize directive
- Step 4: Save and restart your web server
- How to prevent Warning: POST Content-Length and memory size
- jave.web
- People also ask
- 2 Answers
- Before you apply the solution:
- Add this to your .htaccess:
- It is not that evil as it seems to be:
- Even XAMPP’s PHP «itself» recommends it for production:
- jave.web
How to Fix the POST Content-Length Exceeded Error
In this tutorial, we’re going to provide details regarding the error message POST Content-Length Exceeded in WordPress, including meaning and ways to fix it.
What Does the Error Mean?
By default, the maximum amount of data that can be transferred via PHP is 5MB. If you are a WordPress administrator and attempt to upload a file larger than this value, your upload will be interrupted and your web page will produce a POST Content-Length Exceeded warning.
The following screenshot shows an example that illustrates the error POST Content-Length.
How Can I Increase the Maximum Upload Limit in WordPress?
The maximum limit on uploading data in WordPress can be changed by modifying the PHP variables post_max_size and upload_max_filesize, both of which can be found in your web hosting account’s main php.ini file.
AwardSpace offers its users to change these PHP variables in the following two ways:
Note: Both features are only available to our premium hosting account customers. If you own a free hosting plan and are looking to get a premium one, you are welcome to review our offers at our shared hosting page.
Solution #1: Using the AwardSpace PHP Settings Manager
- Sign in to your AwardSpace account via our login portal.
- Under the Advanced Tools area, click on the PHP Settings link.
- Click on the here link in order to access the PHP Settings editor.
- Once you are inside the editor, locate the variables post_max_size and upload_max_filesize.
Solution #2: Generating a custom php.ini file
An alternative way to increase the maximum upload limit is with the creation of a php.ini file.
Create a new file under your WordPress main directory and name it php.ini. Using your favorite editor or our built-in File Manager, open the php.ini file you’ve created and insert the below code into it:
The above set of rules will allow you to upload files via PHP up to 30MB in size.
After you submit the changes, log into your WordPress back-end and retry the upload process. If everything goes as expected, you will receive a system notification that your theme/plugin has been installed.
Fix: POST Content-Length of X bytes exceeds the limit of X bytes.
In this tutorial, we are going to show you how to fix the following PHP warning:
PHP Warning: POST Content-Length of 77870742 bytes exceeds the limit of 8388608 bytes.
This error will occur if the size of a POST request is larger than the limit in your “post_max_size” directive.
If you look at the message carefully, you can see that the Content-Length of the POST request in this case was 77,870,742 bytes. That is roughly 77.87MB.
This is a problem, as the post_max_size directive in our php.ini file is 8,388,608 bytes (8MB).
By default, PHP’s post_max_size directive will be 8MB.
To sum up the issue in this particular case:
- The size limit for a POST request is 8MB.
- However, the size of our POST request is 77.87MB.
As you can see, it is well over the limit. Consequently, both the $_POST and $_FILES superglobal arrays will be empty.
This kind of error is particularly common with file uploads, as the size of an uploaded file can easily surpass the 8MB limit that has been set down in php.ini.
For example, a small video file could end up being 100MB or more. A form that allows the user to upload multiple files at once will also easily surpass this limit.
What is my post_max_size setting?
Here is a quick way to determine what your current post_max_size setting is:
//Print out the value of the post_max_size directive. echo ini_get('post_max_size');
In the PHP snippet above, we printed out the value of the post_max_size setting by using the ini_get function.
In most cases, this will say “8M”.
How to increase your post_max_size setting.
To increase the size limit of your POST requests, you will need to locate your php.ini file and change the post_max_size directive.
By default, it will look like this:
As you can see, it is currently 8MB. If we want to change this limit to 32MB, then we will need to change the directive to:
PHP also allows you to specify gigabytes by using the G character:
In the example above, we set the maximum size of POST data to one gigabyte. Note that you can also completely disable the max size by setting the value to 0 like so:
This will only work if you are using PHP version 5.2.12 or above. However, I would recommend that you do not disable this limit unless you’re 100% sure that you know what you are doing.
Make sure that you save the file and reload your web server after changing this directive. Otherwise, the older limit value will remain in memory.
Can I use the ini_set function to change the post_max_size directive?
The post_max_size directive cannot be changed by using PHP’s ini_set function. Therefore, using the following piece of code will not work:
//Attempting to use ini_set to change post_max_size echo ini_set('post_max_size', '100M');
This is because the directive has a Changeable Mode Value of PHP_INI_PERDIR.
You can change this setting in a php.ini, .htaccess, httpd.conf or .user.ini file.
However, you will be unable to do so using ini_set.
PHP Warning: POST Content-Length of 8978294 bytes exceeds the limit…
This PHP Warning error occurs because the data being posted is larger than the maximum size allowed by the PHP configuration.
To resolve this, you need to increase the post_max_size directive in your PHP configuration file. This directive sets the maximum size of POST data that PHP will accept. By default, the value is usually set to 8MB.
To increase the post_max_size the directive, follow these steps:
Step 1: Locate your PHP configuration file
The location of your PHP configuration file depends on your operating system and the web server. Here are some common locations:
- CentOS: /etc/php.ini
- Ubuntu: /etc/php/7.2/apache2/php.ini
- XAMPP: /opt/lampp/etc/php.ini
- WAMP: C:\wamp64\bin\php\php7.4.9\php.ini
If you’re not sure where your PHP configuration file is located, you can create a new PHP file with the following code:
Save the file in your web server’s root directory and access it via a web browser. Look for the “Loaded Configuration File” row to find the location of your PHP configuration file.
Step 2: Edit the post_max_size directive
Once you’ve located your PHP configuration file, open it in a text editor and search for the post_max_size directive. If it’s not there, you can add it to the end of the file. The line should look like this:
Change the value to a higher number, like 16M. Make sure to use the appropriate unit (M for megabytes, K for kilobytes, G for gigabytes). The new line should look like this:
Step 3: Edit the upload_max_filesize directive
The upload_max_filesize the directive sets the maximum size of uploaded files. You should set this value to the same or a higher value than post_max_size .
Search for the upload_max_filesize the directive in your PHP configuration file and modify it as follows:
Step 4: Save and restart your web server
Save your changes to the PHP configuration file and restart your web server to apply the new settings. The method for restarting your web server varies depending on your operating system and the web server. Here are some common methods:
- CentOS: sudo service httpd restart
- Ubuntu: sudo systemctl restart apache2
- XAMPP: Click the “Stop” button and then the “Start” button in the XAMPP control panel
- WAMP: Click the “Restart All Services” button in the WAMP control panel
After restarting your web server, the “PHP Warning: POST Content-Length of 8978294 bytes exceeds the limit of 8388608 bytes in Unknown on line 0” error message should no longer appear. You can now submit your form or upload your file without any issues.
In conclusion, to resolve the “PHP Warning: POST Content-Length of 8978294 bytes exceeds the limit of 8388608 bytes in Unknown on line 0” error message, you can increase the post_max_size and upload_max_filesize directives in your PHP configuration file and restart your web server.
How to prevent Warning: POST Content-Length and memory size
Currently when user uploads a photo the page says «Warning: POST Content-Length of XXX bytes exceeds the limit of 21000000 bytes in Unknown on line 0″.
I know what that means and I am NOT looking for the solultions like the increasing the max_upload values or even memory_size_limit. Because users may and users will upload terabytes of nonsense even if you explicitly tell them only max 20MB files and only images are allowed.
I am looking for a solution on:
- How to prevent this warning(s) to even happen?
OR at least: - How to prevent displaying of this warning(s)?
EDIT: PLEASE READ ! — Please understand that of course I am handling the error/warning after (since line 1) , problem is this happens on a virtual «line 0» that is why I need to hide the error or prevent it to raise — because I cant put any code before the place where the error happens.
EDIT2: Finally after a very long research and digging I got an idea — it worked — see my own answer.
asked Feb 11 ’14 21:02
jave.web
People also ask
Post-Content-Length Exceeds The Limit error you are getting because your upload size of the theme is more than the set file-max upload file size in php.ini You may also be interested in Fomo Plugins, Email marketing Service and Page Builder Tool
PHP Warning: POST Content-Length of 77870742 bytes exceeds the limit of 8388608 bytes. The error message above will occur if the size of a POST request exceeds the limit that has been set in the post_max_size directive in your php.ini file.
a note to passersby: this error and fix is not specific to WordPress or XAMPP. It is applicable generally to the PHP error POST Content-Length of X bytes exceeds the limit of Y 8388608 bytes is 8M, the default limit in PHP. Update your post_max_size in php.ini to a larger value.
The size limit for a POST request has been set to 8MB. However, the size of our POST request is 77.87MB. As you can see, it is well over the allowed limit.
2 Answers
So after searching instead of working today I finally got an idea how to solve this, it worked, and even didnt cause much damage. But please first understand what you are doing, before doing it. 🙂 As I suggested in one of my comments it is really possible to turn off PHP errors in .htacess — just turn off the PHP startup warnings.
Before you apply the solution:
Note that: after you insert this code to your .htaccess you won’t be able to see any startup error
Also note that: there are more start up errors on line «0» than this one.
Do before: Before you do this you should prepare your script in the way that it should check the uploaded content size and give user a proper information message. The fact that the warning doesnt show DOES NOT mean that you should do nothing about it. It means the EXACT oposite — you should do all that you can to make something at least near-equal to the warning raise — check, double check if you can, handle error and raise your own error message.
Add this to your .htaccess:
php_flag display_startup_errors off
It is not that evil as it seems to be:
Please note that this turns off startup errors only.
So all the regular PHP errors/warnings/notices stays ON 🙂
Even XAMPP’s PHP «itself» recommends it for production:
The php.ini file literaly says:
; display_startup_errors ; Default Value: Off ; Development Value: On ; Production Value: Off
PS: «startup error» seems to be those errors before PHP script is executed itself — these errors are usually trying to «persuade» you that they are on the line 0.
Thanks to my idea and this answer: How to disable notice and warning in PHP within .htaccess file?
EDIT: As this is a php_flag setting, you can of course also set it by default in your php.ini if you have custom instalation of PHP 🙂
answered Sep 19 ’22 02:09
jave.web
The question is
How to prevent Warning: POST Content-Length
the answer is, without edit any config value, put this code at the very start of the file that will receive the form to be processed:
That is. No more warning, as well anything else you do not want as output on your page. After, as suggested elsewhere you can decide what to do with:
if($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST) && empty($_FILES) && $_SERVER['CONTENT_LENGTH'] > 0)
Maybe also chunk the file, if in another way you pass correct values about file to be processed by Php.
as explained here Warning: POST Content-Lenght .
answered Sep 19 ’22 02:09