Page 1 of 1

"Download Complete" notification ?

Posted: Tue May 04, 2010 6:43 am
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

Re: "Download Complete" notification ?

Posted: Tue May 04, 2010 9:30 am
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