Friday, August 22, 2008

Upload Bigger files

Guys, As we have discussed, file upload in php is quite easier,
If you are newer to php file upload please refer to
(http://softwareguy82.blogspot.com/2008/08/simple-file-upload-in-php.html).

In this article we will discuss how to upload files with bigger size (200 mb / 300 mb or even more).

1) One approach is to mention MAX_FILE SIZE in the form itself.
<html>
<body>
<form enctype="multipart/form-data" action="upload.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
Choose a file to upload: <input name=" file" type="file" />
<input type="submit" value="Upload" />
</form>
</body>
</html>


By this approach, you can limit file size.

2) php.ini change
Php has global settings in php.ini for max file size.
Here only change in max_file_size is not sufficient. Some other corresponding settings are also needed.

Change following values
upload_max_filesize = 200M
post_max_size = 250M
max_execution_time = 900 (or -1 will also do, but be careful, this will allow hackers to attack on your server)
max_input_time = -1
memory_limit = 250M

That’s it. This setting should allow to upload files with bigger filesize.

3) On shared server, its not possible to customize php.ini. This is biggest hurdle.
And ini_set() doesn’t work for above said variables.
One common practice is to use .htaccess provided you are working with apache server.

In htaccess file paste following lines
php_value upload_max_filesize 200M
php_value post_max_size 250M
php_value max_execution_time 900
php_value max_input_time -1
php_value memory_limit 250M

If you are still facing problem while uploading; check apache config setting (httpd.conf) “AllowOverride” for directory level. That’s should be ALL.

That’s it guys, This should wrk.
Send me your feedback on ninad.blog@gmail.com


No comments: