PHP Code

PHP Upload Large Files

Just a quick tip here for uploading large files in PHP. I had to write a form to upload fairly large files (100+ megs). At first I tried using ini_set to up the PHP upload settings:

ini_set('upload_max_filesize', '150M');
ini_set('memory_limit', '512M');
ini_set('max_execution_time',3600);
ini_set('post_max_size', '150M');

This should increase the maximum size of a file that can be uploaded. The memory limit and max execution time of the script usually needs to be increased as well in order to deal with the bigger file. I’ve only ever needed to increase the memory limit before and this has always worked for me but for some reason the upload size increases weren’t being set. You can see this by adding phpinfo(); after the ini_set directives to see all the PHP variables. I got a good tip from the PHP Freaks Forum about upping these limits in the htaccess file instead:

php_value memory_limit 512M
php_value max_execution_time 3600
php_value post_max_size 150M
php_value upload_max_filesize 150M

I added the above into an htaccess file for the folder I was working in and this fixed all my issues. I hope this helps out anyone else.

Continue Reading