How to Upload Huge Images to WordPress

Well, this actually applies not just to WordPress but to most PHP applications, it’s just that with WordPress market share close to 60% this is the platform where you most frequently see the problem to manifest. It looks like this:
Maximum upload file size: 2M

The problem is not really WordPress’, it’s in the PHP default limit of 2 Megabytes for any file upload. Why does PHP implement this limit? Well, they are caring about people hosting their PHP applications on servers with relatively low memory (say 1Gb) and disk space (100Mb, for instance). If PHP didn’t not implement this limit then it would be too easy to exhaust all RAM and run out of free disk space too.

So if you’re absolutely sure that you have enough of RAM and disk space then you can go ahead and increase the limit. This is done in the php.ini file (if you don’t know where it is then do something like find / -name php.ini, which will potentially take a long time to find the file) or check the places it’s typically residing in, like /etc/php/php.ini.

You need to add the following lines (or editing existing parameters):
upload_max_filesize=40M
max_file_uploads=1000
post_max_size = 100M
memory_limit=500M

The first 3 parameters are quite obvious, they increase the maximum file size overall, the number of files you can upload simultaneously and the overall POST request size. These specific values, for instance, will allow me to upload two 40Mb files or one hundred 1Kb files at once.
The last parameter is a bit less obvious. When you upload a huge file to WordPress it immediately starts processing it, for instance creating thumbnails of all sizes. This takes RAM. And for large files it takes a lot of RAM. So, naturally, you need to increase the RAM limit as well. For instance these specific settings allowed me to upload and process a 12000x8000px .jpeg. Interestingly, not increasing this parameter causes “HTTP error” error in wordpress, even though the problem is not in the file upload, but in its processing.
Why not set these values to 1Tb each then? Well, you actually want to keep them as small as possible (though still large enough for the purpose of uploading large files) for the same reasons described above. No matter how much RAM or disk space you have, making these parameters too large is a potential risk of running our of your server’s resources.

Leave a Reply