PHP Post Max Size
This tutorial demonstrates how to increase the maximum post size in PHP.
PHP Post Max Size
The post_max_size
is a property from the php.ini
file, which decides what will be the maximum size of the post. Setting the post_max_size
is very easy in PHP and can be done by two methods.
Change PHP Post Max Size From PHP.INI
Follow the steps below to change the post_max_size
from the php.ini
file.
-
Go to your PHP directory.
-
Open the
php.ini
file. -
Search for
post_max_size
. -
Increase the post size from 8 MB to whatever you want for maximum post size.
-
Now, to increase the maximum upload file size, search for
upload_max_filesize
. -
Increase the maximum upload file size by your choice.
-
If you want to increase the file number for upload, that can be done by the option given under the
max_file_uploads
option. -
Once you have made changes, save the
php.ini
and close it. -
It is necessary to restart the server after changes are made in the
php.ini
. -
Open the Command Prompt.
-
Go to your server’s
bin
directory; in our case, it is Apache. -
Run the following command.
httpd -k restart
-
If there is no error, that means the server is restarted, and changes in
post_max_size
,upload_max_filesize
, andmax_file_uploads
are successful.
Change PHP Post Max Size From .htaccess
The .htaccess
file is from the server on which the PHP is running. To change the post_max_size
from .htaccess
, first, we need to enable it; follow the steps below to enable the .htaccess
file.
-
Go to your server directory, in our case Apache.
-
Go to the
conf
folder and openhttpd.conf
. -
Search for the following line in the
httpd.conf
file.#LoadModule rewrite_module modules/mod_rewrite.so
-
Remove the
#
from the line. -
Now search for
AllowOverride
and ensure it is set toAll
or any combination of keywords; the value forAllowOverride
cannot benone
. -
Save the
httpd.conf
file and close it. -
Restart the Apache.
Once the .htaccess
is enabled in the Apache now, we can assign post_max_size
through the .htaccess file
. Follow the steps below.
-
First, we need to create a
.htaccess
file. The file should be in the root directory; in the case of Apache, the root directory for our application ishtdocs
. -
Go to
C:\Apache24\htdocs
and create a text file. -
Copy the following code according to your size parameter into the text file.
php_value post_max_size 25M php_value upload_max_filesize 25M
-
The above code will increase the maximum post size and upload file size to 25 MB each.
-
Save the text file as
.htaccess
and again make sure the file is in the root directory. -
Once you close the file, the new parameters will be set; there is no need to restart the server in this case.
Sheeraz is a Doctorate fellow in Computer Science at Northwestern Polytechnical University, Xian, China. He has 7 years of Software Development experience in AI, Web, Database, and Desktop technologies. He writes tutorials in Java, PHP, Python, GoLang, R, etc., to help beginners learn the field of Computer Science.
LinkedIn Facebook