Read file as its being uploaded

2019-07-28 05:54发布

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?

2条回答
ら.Afraid
2楼-- · 2019-07-28 06:06

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.

查看更多
forever°为你锁心
3楼-- · 2019-07-28 06:16

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.

查看更多
登录 后发表回答