"Download Complete" notification ?

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
MiniMonty
Forum Contributor
Posts: 196
Joined: Thu Sep 03, 2009 9:09 am
Location: UK

"Download Complete" notification ?

Post by MiniMonty »

Hi all,

after a big old search I couldn't find anything to help so I'm asking here :D

Users will download a 4meg pdf from a simple hyperlink and I need a way to tell the script when the download is complete.
i.e. when the user has got the whole file. Can't find anything - anyone got any ideas ?

Best wishes
Monty
rnoack
Forum Commoner
Posts: 34
Joined: Mon May 03, 2010 12:38 am

Re: "Download Complete" notification ?

Post by rnoack »

Do you need code? or just the idea?

Try creating a php file to server the download. You can do this by serving the headers and then echoing the file in a while loop.
Here's some example:

Code: Select all

<?php 
$filename = < INSERT FULL SERVER PATH TO FILENAME HERE i.e.  /home/users/www/.......  >;
if (file_exists($filename))
{
	header("Cache-Control: public");
	header("Content-Description: File Transfer");
	header('Content-disposition: attachment; filename='.basename($filename));
	header("Content-Type: application/download");
	header("Content-Transfer-Encoding: binary");
	header('Content-Length: '. filesize($filename));
	flush();
	$fp = fopen($filename, "r");
	while (!feof($fp))
	{
		echo fread($fp, 65536);
		flush();
	}
	fclose($fp);		

        <<<<< INSERT CODE YOU WANT TO DO WHEN D/L COMPLETED HERE >>>>>>>>>>>>

}
else 
{
	echo "File not found.";
}
?>

of course this code only means the web server "served" the file, and not 100% necessarily that the user actually received it. but I think this is the best you will get unless there is some other trick
Post Reply