在 PHP 中使用分块上传 1GB 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2447837/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Upload 1GB files using chunking in PHP
提问by rjha94
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.
我有一个 Web 应用程序,可以接受最多 4 MB 的文件上传。服务器端脚本是 PHP,Web 服务器是 NGINX。许多用户要求大幅增加此限制以允许上传视频等。
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.
然而,对于这个问题,PHP 似乎没有简单的解决方案。首先,在客户端,我正在寻找可以让我在传输过程中分块文件的东西。SWFUpload 似乎没有这样做。我想我可以使用 Java FX ( http://blogs.oracle.com/rakeshmenonp/entry/javafx_upload_file)流式上传,但我在 PHP 中找不到任何等效的 request.getInputStream 。
Increasing browser client_post limits or php.ini upload or max_executiontimes 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.
增加浏览器 client_post 限制或 php.ini 上传或max_execution时间并不是真正大文件(~1GB)的真正解决方案,因为浏览器可能会超时并考虑存储在内存中的所有 blob。
Is there any way to solve this problem using PHP on server side? I would appreciate your replies.
有没有办法在服务器端使用 PHP 来解决这个问题?我将不胜感激您的答复。
回答by Dean Rather
回答by Bart van Heukelom
"but I can not find any equivalent of request.getInputStream in PHP. "
“但我在 PHP 中找不到任何等效的 request.getInputStream。”
fopen('php://input');perhaps?
fopen('php://input');也许?
回答by rjha94
I have created a JavaFX client to send large files in chunks of max post size (I am using 2 MB) and a PHP receiver script to assemble the chunks into original file. I am releasing the code under apache license here : http://code.google.com/p/gigaupload/Feel free to use/modify/distribute.
我创建了一个 JavaFX 客户端,以最大帖子大小(我使用 2 MB)的块发送大文件和一个 PHP 接收器脚本,用于将块组装成原始文件。我在这里发布 apache 许可下的代码:http: //code.google.com/p/gigaupload/随意使用/修改/分发。
回答by Amjad Farooq
回答by Konsole
Take a look at tus protocolwhich 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 vimeofrom May, 2017.
看看tus 协议,它是一种基于 HTTP 的协议,用于可恢复的文件上传,因此您可以在中断的地方继续,而无需再次上传整个数据,以防万一。从 2017 年 5 月起,vimeo也采用了该协议。
You can find various implementations of the protocol in different languages here. In your case, you can use its javascript client called uppyand use golangor phpbased server implementation in a server.
您可以在此处找到不同语言的协议的各种实现。你的情况,你可以使用一个叫做它的JavaScript客户端uppy和使用golang或PHP基于服务器中的服务器实现。
回答by Mahdi
you can use this package
你可以使用这个包
it supports resumable chunk upload.
它支持可恢复的块上传。
in the examples/js-examples/resumable-chunk-uploadexample , you can close and re-open the browser and then resume not completed uploads.
在examples/js-examples/resumable-chunk-upload示例中,您可以关闭并重新打开浏览器,然后恢复未完成的上传。
回答by Chris
How about using a java applet for the uploading and PHP for processing..
如何使用 java 小程序上传和 PHP 进行处理..
You can find an example here for Jupload: http://sourceforge.net/apps/mediawiki/jupload/index.php?title=PHP_Example
您可以在此处找到 Jupload 的示例:http: //sourceforge.net/apps/mediawiki/jupload/index.php?title =PHP_Example
回答by Zak
You can definitely write a web app that will accept a block of data (even via a POST) then append that block of data to a file. It seems to me that you need some kind of client side app that will take a file and break it up into chunks, then send it to your web service one chunk at a time. However, it seems a lot easier to create an sftp dir, and let clients just sftp up files using some pre-existing client app.
您绝对可以编写一个接受数据块(甚至通过 POST)的 Web 应用程序,然后将该数据块附加到文件中。在我看来,您需要某种客户端应用程序来获取文件并将其分解为多个块,然后一次一个块地将其发送到您的 Web 服务。但是,创建 sftp 目录似乎要容易得多,并让客户端使用一些预先存在的客户端应用程序 sftp 文件。

