|
Posted by Toby A Inkster on 02/15/07 10:06
andrew.zahra wrote:
> Is there any way to track completion of a download with PHP? I would
> like to be able to check if a download completed successfully.
Yes, there is -- if the downloaded file has been served through PHP. That
is:
<?php
// This file is "myvid.php".
session_start();
$_SESSION['download_attempts'][] = 'myvid';
header("Content-Type: video/mpeg");
print file_get_contents("myvid.mpeg");
if (!connection_aborted())
$_SESSION['download_successes'][] = 'myvid';
?>
Now to link to the video, use:
<a href="myvid.php" type="video/mpeg">myvid</a>
And to check to see download status:
<?php
session_start();
if (in_array('myvid', $_SESSION['download_attempts']))
{
if (in_array('myvid', $_SESSION['download_successes']))
{
echo 'User fully downloaded myvid';
}
else
{
echo 'User partially downloaded myvid';
}
}
else
{
echo 'User has not attempted to download myvid';
}
?>
That should work, though web proxies may complicate matters. (e.g. web
proxy downloads whole file, but only transmits part of it to client.)
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there!
[Back to original message]
|