PHP Maximum File Upload Size Control

Posted in Articles

Tweet This Share on Facebook Bookmark on Delicious Digg this Submit to Reddit

Certain web applications can allow an user or an administrator to upload a file from their computer to the Web Server. Once in a while, you may encounter an error when the file that you are trying to upload is too large. Some default PHP installation is set to allow a maximum of file upload size of 2 MB. So try uploading a file less than that to see if it is file size that is causing the upload problem.

There are two constraints that can limit the file upload size: 1) the code in the web application, and 2) the web host server configuration. The actual limit would be the lower of the two.

Setting Media Upload File Size in Joomla

If the web application is a content management system such as Joomla, then the administrator may be able to set the upload file size in the administrator settings. For Joomla 1.5, it would be in “Site -> Global Configuration -> System -> Media Settings -> Maximum Size”.

PHP Upload File Size

Linux web host server that runs PHP, has a PHP.ini configuration file. Among its configuration parameters are upload_max_filesize and the post_max_size. These can limit the maximum file size that can be uploaded to the server via a webpage regardless of the code of the webpage. So try fiddling with these two parameters in the php.ini file.

Note that there can be multiple locations where the php.ini configuration file exists. You may have to change it in more than one place. You can determine the values of the configuration file that are in effect, by placing a PHP file that displays phpinfo() at the desired location that you want to check. The phpinfo() display can also tell you the php.ini file location. Remember to remove this after checking.

The upload_max_filesize specifies the maximum size of the uploaded file.

The post_max_size sets the maximum size of posted data which affect the file upload site.

Because uploading large files require execution time, max_execution_time and max_input_time can also affect the upload. As can memory_limit.

Another parameter that might affect the upload is file_uploads. Make sure that parameter is set to be “1”.

Alternatives if unable to adjust Max limit of Upload File Size

Depending on the web host, some may not let you adjust the php.ini file settings. You can zip up the file to be uploaded and hope that the compressed size is smaller than the limit. Alternatively you can manually upload the file to the server using an FTP client. See tutorial on how to use the free FTP client FileZilla.


Share This