Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload very large files(>5GB)

I need your help. I want to create a upload script with HTML, JQuery and PHP. Is it possible to write a script, that can upload very large files(> 5 GB)?

I've try it with FileReader, FormData and Blobs, but even with these, i can't upload large files(my browser crashes after selecting a large file).

PS: I want to write it myself. Don't post any finished scripts.

Regards

like image 733
Sylnois Avatar asked Feb 19 '23 16:02

Sylnois


1 Answers

Yes. I wrote PHP to upload file exactly 5GB more then one year ago.

FileReader, FormData and Blobs will fail because they all require pre-process and convert in javascript before it get upload.

But, you can easily upload large file with plain simple XMLHttpRequest.

var xhr=new XMLHttpRequest();
xhr.send(document.forms[0]['fileinput']);

It is not a standard or documented way, however, few Chrome and Firefox do support. However, it send file content as is, not multipart/form-data, not http form-data. You will need to prepare your own http header to provide additional information.

var xhr=new XMLHttpRequest(), fileInput=document.forms[0]['fileinput'];
xhr.setRequestHeader("X-File-Name", encodeURIComponent(getInputFileName(fileInput)));
xhr.setRequestHeader("X-File-Size", getFileSize(fileInput));
xhr.send(fileInput);

PS. well, actually it was not PHP. It was mixed PHP and Java Servlet.

like image 90
Dennis C Avatar answered Feb 21 '23 06:02

Dennis C