在PHP或Java中实现一个大(1GB或更多)文件上传网站的最佳方式是什么? [英] What is the best way to implement a big (1GB or more) file uploader website in PHP or Java?

查看:100
本文介绍了在PHP或Java中实现一个大(1GB或更多)文件上传网站的最佳方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP或Java中实现一个大(1GB或更多)的文件上传网站的最好方法是什么?使用PHP或Java上传的默认方式会导致内存空间不足,并极大地降低网站的运行速度。

解决方案

在客户端打开文件是不明智的,将内容全部读到内存中,然后关闭发送的内容,正是因为内容可以超过可用内存。

一个替代方法是打开文件,读取它的一大块(记住最后一个块的结束当然),关闭文件,上传到服务器,并重新组装在服务器端的文件附加到以前的块。这不是一个简单的过程,而应该考虑资源管理,IO错误和同步等问题,尤其是在与多个线程并行工作时。

What is the best way to implement a big (1GB or more) file uploader website in PHP or Java? Using the default way of uploading in PHP or Java results in running out of RAM space and slowing the website very dramatically.

解决方案

It would be unwise to open the file on the client side, read its whole content to memory, close it and then start sending the contents, precisely because the contents can exceed the available memory.

One alternative is to open the file, read a chunk of it (remembering where the last chunk ended of course), close the file, upload to the server, and reassemble the file on the server side by appending to previous chunks. This is not a trivial procedure, and should take into consideration things like resource management, IO faults and synchronization, especially when working in parallel with multiple threads.

这篇关于在PHP或Java中实现一个大(1GB或更多)文件上传网站的最佳方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆