Configure file upload size and PHP memory in PHP.ini

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 limit

You can increase the maximum upload size by modifying PHP.ini file. To change the upload limit you need to modify two keys: upload_max_filesize and post_max_size.

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 PHP.ini keys for file size upload:

upload_max_filesize = 16M
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:

memory_limit = 32M

Editing PHP.ini

This largely depends on your hosting. Some hosting companies allow you to directly edit PHP.ini, some hosting companies have an editor where you can visually modify desired values. Usually, you need to restart your web server (Apache or Nginx) for new values to take effect.

If you are not sure how to modify PHP.ini on your server, it is best to contact your hosting company support and ask them to make changes you need.

Rate this article

You are not allowed to rate this post.

Leave a Comment