Core PHP PHP

How to Upload Large Files in PHP ?

How to Upload Large Files in PHP ?

Upload Large Files in PHP

Uploading files in PHP is very easy. If you want to upload without ftp, from you PHP script its very easy to upload.

In PHP by default 2MB permit to upload, If you want to upload more than 2 MB files you need to modify php.ini , .htaccess or .php file.

There are two PHP configuration options control the maximum upload size: upload_max_filesize and post_max_size. Both are set , “24M” for 24 megabyte file sizes.

However, you also need to set execution time. PHP normally timeout after 30 seconds, but a 24MB file would take at least 3-5 minutes or depend upon you net speed to upload. You need to set PHP max_input_time and max_execution_time to something like 420 (7 minutes specified in seconds).

These options are set on php.ini file confituration so they apply to all application. If you are using apache the alternative configuration settings in .htaccess file in you application.

.htaccess files configuration

php_value upload_max_filesize 10M

php_value post_max_size 10M

php_value max_input_time 300

php_value max_execution_time 300

You can define the constraints within your PHP application:

.php file configuration

ini_set(‘upload_max_filesize’, ’10M’);

ini_set(‘post_max_size’, ’10M’);

ini_set(‘max_input_time’, 300);

ini_set(‘max_execution_time’, 300);

PHP also provides a function name set_time_limit() so you need not to set max_execution_time directly.

Leave a Reply

Your email address will not be published. Required fields are marked *