views:

48

answers:

2

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?

A: 

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.

wvd
+2  A: 

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.

Pekka