Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload 1GB files using chunking in PHP

I have a web application that accepts file uploads of up to 4 MB. The server side script is PHP and web server is NGINX. Many users have requested to increase this limit drastically to allow upload of video etc.

However there seems to be no easy solution for this problem with PHP. First, on the client side I am looking for something that would allow me to chunk files during transfer. SWFUpload does not seem to do that. I guess I can stream uploads using Java FX (http://blogs.oracle.com/rakeshmenonp/entry/javafx_upload_file) but I can not find any equivalent of request.getInputStream in PHP.

Increasing browser client_post limits or php.ini upload or max_execution times is not really a solution for really large files (~ 1GB) because maybe the browser will time out and think of all those blobs stored in memory.

Is there any way to solve this problem using PHP on server side? I would appreciate your replies.

like image 259
rjha94 Avatar asked Mar 15 '10 14:03

rjha94


People also ask

How can I upload large files over 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 PHP values are 2 MB for upload_max_filesize, and 8 MB for post_max_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.

How can I upload 10 MB file in PHP?

Two PHP configuration options control the maximum upload size: upload_max_filesize and post_max_size . Both can be set to, say, “10M” for 10 megabyte file sizes. However, you also need to consider the time it takes to complete an upload.


2 Answers

plupload is a javascript/php library, and it's quite easy to use and allows chunking.

It uses HTML5 though.

like image 139
Dean Rather Avatar answered Oct 14 '22 17:10

Dean Rather


Take a look at tus protocol which is a HTTP based protocol for resumable file uploads so you can carry on where you left off without re-uploading whole data again in case of any interruptions. This protocol has also been adopted by vimeo from May, 2017.

You can find various implementations of the protocol in different languages here. In your case, you can use its javascript client called uppy and use golang or php based server implementation in a server.

like image 43
Konsole Avatar answered Oct 14 '22 19:10

Konsole