file download monitoring (possible?)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thehustler
Forum Newbie
Posts: 2
Joined: Wed Jul 20, 2005 3:16 pm

file download monitoring (possible?)

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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
User avatar
IceMetalPunk
Forum Commoner
Posts: 71
Joined: Thu Jul 07, 2005 11:45 am

Post 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 ;) :)
thehustler
Forum Newbie
Posts: 2
Joined: Wed Jul 20, 2005 3:16 pm

Post by thehustler »

Yes, I think that's going to work.
Thanks.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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....
Post Reply