Page 1 of 1

file download monitoring (possible?)

Posted: Wed Jul 20, 2005 3:20 pm
by thehustler
Hi,
I'd like to use a php page as a proxy in order to download a file.
My question is, how do I go about ensuring that the entire file has been downloaded.
i.e. if the user cancels the download half way through I need to know.

Posted: Wed Jul 20, 2005 4:09 pm
by Chris Corbyn
Hmm... I'm not sure you can really do that with PHP.

The only thing I can think of is to use sockets *somehow* and I really wouldnt know how, which remain open and pass the data using a socket.

Someone else can probably rubbish me and give the correct method though :P

Posted: Wed Jul 20, 2005 4:49 pm
by IceMetalPunk
I would do something like this:

Code: Select all

<?php
$filename="http://www.somedomain.com/somefile.ext";
$data=file_get_contents($filename);
$mime=mime_content_type($filename);
header("Content-type: $mime");
echo $data;

/*Since we got to this point, the file should be done, so do whatever you want here.*/
?>
This way, the part where the comment is can only be reached once all the data has been transferred.

-IMP ;) :)

Posted: Wed Jul 20, 2005 5:20 pm
by thehustler
Yes, I think that's going to work.
Thanks.

Posted: Wed Jul 20, 2005 5:27 pm
by Chris Corbyn
Hmm... I think that only works if the file is < 8MB (unless you tweak php.ini) and you *may* have to fiddle with output buffering too...

Try testing it by dumping a text file at the end or something....