≡ Menu

PHP – Increase maximum upload file size limit

The question – I have a script that allows users to upload files to the server. Sometimes, when the file is large (40 megabytes), it errors out saying that the file is too big for uploading. I need to increase the upload file size limit. How do I do that? Is there an Apache or PHP directive that can be used to do this?

There are two PHP variables that can be used to increase the maximum upload file size limit:

upload_max_filesize = 50M
post_max_size = 50M

You need to set these to the maximum file size that you expect.

First, locate your php.ini file:

ewhathow@ewhathow.com [~]# php -i | grep php.ini
Configuration File (php.ini) Path => /usr/local/lib
Loaded Configuration File => /usr/local/lib/php.ini
ewhathow@ewhathow.com [~]#

Open the file and add or update the file size limits:

upload_max_filesize = 50M
post_max_size = 50M

That’t it! Now if you are on a shared web hosting server, you might not have access to the global php.ini file. In that case, you can use the .htaccess file in the directory in which your uploading PHP script is located:

Add the following lines to your .htaccess file:

<IfModule mod_php5.c>
php_value upload_max_filesize 50M
php_value post_max_size 50M

The IfModule statement checks on whether you are running PHP as an Apache module. If you are, you can set the values of PHP variables using the php_value directive. If you are not, then setting these values might result in a 500 Internal Server Error, and the IfModule check is there to prevent this from happenning.

So these were two methods by which you can increase the maximum upload file size limit in PHP. I hope this will solve your problems!

{ 0 comments… add one }

Leave a Comment