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!
after a big old search I couldn't find anything to help so I'm asking here
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 ?
<?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