How to Increase Your PHP Upload Limit

Picture this:  You have a shiny new web application that allows your website’s users to upload videos through a web interface.  They are meant to be short videos that do not take up much space or bandwidth (100MB or less), but when you finally open the doors to let the users have at it, you run into a problem.  Your PHP script times out and gives an error to users trying to upload videos.

Hopefully, you will avoid a situation like this by planning better ahead of time, but the same type of scenario could occur in any number of situations.  The result is always the same, your upload fails, and you are left looking for solutions.  For a dedicated server that uses PHP, the solution is actually quite simple.  For security purposes, PHP has a browser upload limit, something that prevents unauthorized users from going crazy with a web form.  Assuming you trust your users or the script you have created to give proper authorization to them, you can easily raise the limit.

To do this, you will need to edit your php.ini file.  On many Linux distributions, you can find the file at /etc/php.ini.  Assuming you want to change these settings for the entire server, edit the file as root, changing the following line to the limit you want:

file_uploads = On
upload_max_filesize = 60M //needs to be in {x}M format

In the above example, the maximum upload size is set to 60 MB.  Keep in mind that the global php.ini file will affect all PHP scripts on the server, so if you host other users’ websites, you may want to keep the number low and use a local php.ini file for a particular virtual host.