How to change PHP max upload file size

Published by Subhas Fagu on 25/04/09 23:56:21
Last edited on 26/04/09 00:02:30

With all the new web apps popping up, the demand for the exchange of media such as high res photos and music clips are becoming more prominent. To accomplish this, we need to tell our webserver/PHP to allow larger than conventional upload file sizes. Traditionally, the max upload size is around 2mb, anything more will yield an error 500 due to a timeout. There are two ways (that I know of) to change the php upload limit.

The first is done by editing the php.ini file. This is normally the case if you have your own dedicated or virtual server. There may be multiple php.ini files throughout your system. The main one is typically found in /etc/php.ini which would govern all PHP scripts. Furthermore you can include php.ini file in each folder that you wish to apply different settings to. In any case the, below are the fields you want to change.

php.ini

upload_max_filesize = 10M ;
post_max_size = 20M ; 

An alternative is to using the php.ini file is to use .htaccess. By just placing a.htaccess file in your root folder, all folders beneath it will also have the change. The code to change your PHP max file upload size is as follows:

RewriteEngine On
php_value post_max_size 20M
php_value upload_max_filesize 10M
php_value max_execution_time 6000000 

Notes: Choose your values carefully, know your audience and monitor the number of users. Always test/plan for worst case scenarios; 500 users uploading 10mb at the same time = 5,000mb bandwidth. This could easily annoy your web host provider.

About the Author

Subhas Fagu is an energetic person who you will never catch doing the same thing twice…unless it’s working. He’s always engaged in new concepts, frameworks, operating systems, applications, you name it and you’ve got a conversation. Being a founder of Techlicity Ventures, he's been a key in the business and technical development of all previous and upcoming projects. Subhas contributes a wide variety of perspectives to all projects to ensure risk coverage and smooth deployment.

Bookmark and Share
Blog Widget by LinkWithin
blog comments powered by Disqus

Valid XHTML 1.0!