上传非常大的文件(> 5GB) [英] Upload very large files(>5GB)
问题描述
我需要你的帮助。我想用HTML,JQuery和PHP创建一个上传脚本。
是否可以编写一个脚本,可以上传非常大的文件(> 5 GB)?
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)?
我试用FileReader,FormData和Blobs ,但即使有这些,我也无法上传大文件(我的浏览器在选择大文件后崩溃)。
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:我想自己写。不要发布任何已完成的脚本。
PS: I want to write it myself. Don't post any finished scripts.
问候
推荐答案
是。我编写PHP来上传文件比一年前多5GB。
Yes. I wrote PHP to upload file exactly 5GB more then one year ago.
FileReader,FormData和Blob将失败,因为它们都需要预处理并在javascript之前转换为javascript上传。
FileReader, FormData and Blobs will fail because they all require pre-process and convert in javascript before it get upload.
但是,您可以使用简单的XMLHttpRequest轻松上传大文件。
But, you can easily upload large file with plain simple XMLHttpRequest.
var xhr=new XMLHttpRequest();
xhr.send(document.forms[0]['fileinput']);
这不是标准或文档化方式,但很少有Chrome和Firefox支持。但是,它按原样发送文件内容,而不是multipart / form-data,而不是http form-data。
您需要准备自己的http标头以提供其他信息。
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。好吧,实际上它不是PHP。它混合了PHP和Java Servlet。
PS. well, actually it was not PHP. It was mixed PHP and Java Servlet.
这篇关于上传非常大的文件(> 5GB)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!