Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

1GB file upload using php

I am trying to upload a file of 1GB size using php script and it works perfectly if file size is less than 20MB, but when I increase the file size than after pressing upload button on website, it uploads the file (I guess as it takes few minutes) and after that, instead to execute upload.php, my firefox asks me to download upload.php, so I guess, file is being uploaded but my php script fails to execute.

Also after searching in google I found following settings for php.ini which I made and my php_info() function shows me that settings have been changed..

/*php.ini start*/

memory_limit = 512M

post_max_size = 15000M

file_uploads = On

upload_max_filesize = 15000M

max_input_time = 20000

max_execution_time = 20000

session.gc_maxlifetime = 20000

/*php.ini end*/

like image 485
Sanniv Avatar asked Oct 01 '10 03:10

Sanniv


People also ask

How to upload large files above 500mb in PHP?

By changing the upload_max_filesize limit in the php. ini file. By implementing file chunk upload, that splits the upload into smaller pieces an assembling these pieces when the upload is completed.

What is the max upload file size in PHP?

The default values for PHP will restrict you to a maximum 2 MB upload file size.

Can we upload file of any size to a PHP application?

By default, PHP file upload size is set to maximum 2MB file on the server, but you can increase or decrease the maximum size of file upload using the PHP configuration file ( php. ini ), this file can be found in different locations on different Linux distributions.


2 Answers

The limit on file size uploads is limited by a LOT more than just PHP. PHP has its limits, Apache has its limits, many web services have their own limits, and then you have the limit on the /tmp directory size which could be set by user permissions on a shared host. Not to mention just running out of hard drive space!

Your php.ini looks good, but as was already suggested- check the LimitRequestBody in Apache and make sure your web service allows this.

One common solution when you need to upload very large files is to use Flash or Java on the client-side since these have access to the client's actual file system. The Flash/Java can then break the file into small pieces which are sent one at a time and re-assembled on the server side. This has multiple benefits. First, you can resume broken downloads. Second, you don't have to worry about any scripts timing out. Third, it bypasses any possible file system limits that may be in play from PHP, Apache, web services, or other sources.

like image 93
stevendesu Avatar answered Sep 28 '22 08:09

stevendesu


Check that your web server also allows such large uploads. On Apache the setting is LimitRequestBody. This limit is be applied long before PHP ever enters the picture and cannot be changed/overriden from within PHP.

like image 26
Marc B Avatar answered Sep 28 '22 09:09

Marc B