Category: PHP5

Added: 14th of January 2016

Viewed: 2426 times

How to upload files larger than 2MB using PHP5

It seems my webhosting providers impose a 2MB limit on file uploads through PHP. It seems fair to me, but on the other hand if your running a website that requires your users to upload images, not all of them are going to understand the limits or understand how to reduce the size of the image to bring it under the 2MB limit.

Unless your webhosting provider gives you access to your own PHP configuration file, one solution is to override the PHP settings by creating an .htaccess file, which specifies the max filesize, and post max size.

If your using Linux create a new file on your desktop named .htaccess then copy paste the following code.

Save the file and upload this to your webspace. After this you should be able to upload files, images and other media larger than 2MB

php_value upload_max_filesize 12M
php_value post_max_size 12M
php_value max_execution_time 300
php_value max_input_time 300

I set the limit to 12MB which is suitable for my requirements, but can be set up to 64MB

Other Tips & Tutorials


Convert all characters to Upper or Lower case in PHP5

Posted: 7th of October 2020

Views: 629


Get the day of the week for a specified date using PHP5

Posted: 17th of January 2016

Views: 2274


How to upload files larger than 2MB using PHP5

Posted: 14th of January 2016

Views: 2426


Preserve line breaks in PHP. nl2br function

Posted: 21st of December 2015

Views: 5430


Convert a Unix timestamp to date and time using PHP

Posted: 18th of December 2015

Views: 2597


How to validate a form using PHP5

Posted: 15th of December 2015

Views: 1504


Count the number of elements in a PHP array using the count() function

Posted: 15th of December 2015

Views: 1403


Pass ampersand through query strings in URL using PHP5

Posted: 27th of November 2015

Views: 2956