读取正在上传的文件

发布于 2024-08-29 21:20:29 字数 83 浏览 3 评论 0原文

默认情况下,在上传的文件完全传输到服务器之前,您无法访问该文件。

解决这个问题并能够在文件上传正在进行时访问“字节流”的最佳方法是什么?

By default you cannot access a file that is uploaded until it has been fully transferred to the server.

What is the best way to get round this and be able to access the 'byte stream' as the file upload is in progress?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青朷 2024-09-05 21:20:29

我认为在 PHP 中最接近这一点的是查看各种进度条解决方案,这些解决方案在将文件上传到 PHP 脚本时为您提供进度条。我不详细了解其中任何一个(我一直等到 SWFUpload 才可以在 Flash 中执行此操作),但是如果您可以获得上传进度,那么您也可能可以获得数据块本身。 (更新:基于 APC 的解决方案不能。它似乎只给出上传进度。)

查看 这个问题,尤其是这个答案这个

这些方法都不是在纯 PHP 中运行的,它们都需要 Perl 或 APC 或其他服务器端的东西才能工作。

最终更新:粗略浏览Raditha Mega Upload 进度条 的 Perl 代码 让我认为这是你最好的选择,因为它似乎正在与正在上传的实际文件进行交互。但没有任何保证。

I think the closest you will get to this in PHP is looking at the various progress bar solutions that give you progress bars while doing file uploads to a PHP script. I don't know any of them in detail (I waited until SWFUpload became available to do this in Flash) but if you can get an upload's progress, it's likely you can get the data chunks themselves, too. (Update: the APC based solution can't. It seems to give the upload progress only.)

Check out this question, especially this answer and this one.

None of the approaches runs in pure vanilla PHP, they all need Perl or APC or other server-side stuff to work.

Final update: A cursory glance at the Raditha Mega Upload progress bar's Perl code makes me think this is your best bet, as it seems to be interacting with the actual file that is being uploaded. No guarantees, though.

手长情犹 2024-09-05 21:20:29

您将需要某种缓冲区,用于附加新数据以及分块读取数据。然后检查是否有新数据并再次读取。

You will need to have some kind of buffer where new data will be appended and where you read in chunks. Then check if there is new data and read that again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文