PHP Post Max Size

Sheeraz Gul Feb 15, 2024
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.

  1. Go to your PHP directory.

    PHP Directory

  2. Open the php.ini file.

    PHP INI

  3. Search for post_max_size.

    Post Max Size

  4. Increase the post size from 8 MB to whatever you want for maximum post size.

  5. Now, to increase the maximum upload file size, search for upload_max_filesize.

    Maximum Upload Filesize

  6. Increase the maximum upload file size by your choice.

  7. If you want to increase the file number for upload, that can be done by the option given under the max_file_uploads option.

    Maximum File Upload

  8. Once you have made changes, save the php.ini and close it.

  9. It is necessary to restart the server after changes are made in the php.ini.

  10. Open the Command Prompt.

  11. Go to your server’s bin directory; in our case, it is Apache.

  12. Run the following command.

    httpd -k restart
    

    Apache Restart

  13. If there is no error, that means the server is restarted, and changes in post_max_size, upload_max_filesize, and max_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.

  1. Go to your server directory, in our case Apache.

  2. Go to the conf folder and open httpd.conf.

  3. Search for the following line in the httpd.conf file.

    #LoadModule rewrite_module modules/mod_rewrite.so
    
  1. Remove the # from the line.

    Apache Httpd

  2. Now search for AllowOverride and ensure it is set to All or any combination of keywords; the value for AllowOverride cannot be none.

    Httpd AllowOverride

  3. Save the httpd.conf file and close it.

  4. 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.

  1. 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 is htdocs.

  2. Go to C:\Apache24\htdocs and create a text file.

  3. 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
    
  4. The above code will increase the maximum post size and upload file size to 25 MB each.

  5. Save the text file as .htaccess and again make sure the file is in the root directory.

    HTACCESS File

  6. Once you close the file, the new parameters will be set; there is no need to restart the server in this case.

Author: Sheeraz Gul
Sheeraz Gul avatar Sheeraz Gul avatar

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

Related Article - PHP Post