> ## Documentation Index
> Fetch the complete documentation index at: https://kb.hosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Setting the PHP maximum upload file size in an .htaccess file

> Learn to increase PHP upload limits using upload_max_filesize and post_max_size in .htaccess.

This article describes how to change the maximum upload file size for PHP scripts by using the **upload\_max\_filesize** and **post\_max\_size** directives in an *.htaccess* file.

<Warning>
  **Important**

  The information in this article only applies to certain types of hosting accounts. To determine whether or not the information below applies to your account, please see [this article](/docs/changing-php-settings-and-versions).

  📘 Note

  This article assumes that you have already set up a custom *.htaccess* file. If you have not already set up a custom *.htaccess* file, please read [this article](/docs/custom-htaccess-files-for-php-settings) first.
</Warning>

## Changing the maximum upload file size

You may want to change the maximum upload file size for your web site. For example, you can set a lower limit to prevent users from uploading large files to your site. To do this, change the **upload\_max\_filesize** and **post\_max\_size** directives in an *.htaccess* file.

To change the maximum upload file size for your PHP scripts, follow these steps:

1. Log in to your account [using SSH](/docs/using-ssh-secure-shell).

2. Use a text editor to add the following line to the *.htaccess* file. Replace **xx** with the maximum upload file size that you want to set, in megabytes:

   ```
   php_value upload_max_filesize xxM
   ```

3. Add the following line to the *.htaccess* file. Replace **xx** with the maximum HTTP POST file size that you want to set, in megabytes:

   ```
   php_value post_max_size xxM
   ```

   > 🚧 Important
   >
   > To ensure that file uploads work correctly, the **post\_max\_size** directive should be a little larger than the **upload\_max\_filesize** . For example, to set a file upload limit of 20 megabytes, you could set the **upload\_max\_filesize** directive to **20M** , and the **post\_max\_size** directive to **21M** .

4. Save the changes to the *.htaccess* file and exit the text editor.

5. To verify that the new setting is active, create a PHP test file that contains the following code in the same directory where the *.htaccess* file is located:

   ```
   <?php phpinfo(); ?>
   ```

6. Load the test file in your web browser, and then search for the name of the directive. The **Local Value** column should display the new setting that you specified in the *.htaccess* file.

## More information

* To view a complete list of PHP directives, please visit [http://www.php.net/manual/en/ini.list.php](http://www.php.net/manual/en/ini.list.php).

* For more information about the **upload\_max\_filesize** directive, please visit [http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize](http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize).

* For more information about the **post\_max\_size** directive, please visit [http://www.php.net/manual/en/ini.core.php#ini.post-max-size](http://www.php.net/manual/en/ini.core.php#ini.post-max-size).

## Related articles

* [Custom .htaccess files for PHP settings](/docs/custom-htaccess-files-for-php-settings)

* [Using PHP directives in custom .htaccess files](/docs/using-php-directives-in-custom-htaccess-files)
