Configure file upload size and PHP memory in .htaccess

WordPress ability to upload files can be limited by the file size or POST request size set in PHP.ini for the PHP. By default, PHP allows upload of files up to 2MB.

Upload size and memory used by PHP can be adjusted through PHP.ini, and you can read about that in the previous article here: Configure file upload size and PHP memory in PHP.ini. But, if you have no access to PHP.ini, you can use .htaccess (for Apache servers).

Upload limit

The second key needs to be higher than the first one because files are usually uploaded as a part of the POST request. If you want to allow 5MB file size, POST max size should be at least 6MB. But, if you want to allow upload of multiple files, you need to know that all files must fit into the POST request limit. So, if you try to upload 5 files, each one 4MB, POST request for this would be at least 22MB in size (there is an overhead data sent along actual size, so that must be taken into account too.

Here is the example of the .htaccess entries for file size upload:

php_value upload_max_filesize 16M
php_value post_max_size 130M

With this, a single file can be up to 16MB, and total post size would be limited to 130MB (allowing up to 8 files each one with 16MB, or 20 files each with up to 6MB). If you set limit low and try to upload a large file, PHP will throw an error. If your POST limit is set too low, you will also get an error from PHP.

Memory size

PHP.ini controls the maximum amount of memory single PHP process can use. This value size depends on the application you are running. For WordPress, it should be at least 64MB. Memory size doesn’t affect total size of files you try to upload, but if your POST request is very large and doesn’t include files, that whole POST block (excluding files) must be able to fit into memory. In most cases, this is not the problem, but you should be aware that PHP memory size can affect POST requests processing.

Here is the example of setting PHP memory:

php_value memory_limit 32M

Editing .htaccess

If your website is on Apache server, .htaccess is in the root of your WordPress website. You can edit it via FTP or through cPanel File Manager.

0
0
1173
Rate this article

You are not allowed to rate this post.

Leave a Comment