By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,526 Members | 1,895 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,526 IT Pros & Developers. It's quick & easy.

Tracking download completion

P: n/a
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.

My first thought is that I might need to use an applet?

Any suggestions appreciated.

Feb 15 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Wed, 14 Feb 2007 23:19:01 -0800, 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.

My first thought is that I might need to use an applet?

Any suggestions appreciated.
According to the PHP manual, scripts are aborted if the client
disconnects. Therefore assuming you're using a PHP script to download the
file if it gets to the line after readfile() (or some such code) then the
client connection is still active and therefore the download completed.

However, you can turn this functionality off so the script always
completes whether the client disconnects or not. So it may be best to use
connection_aborted() to see if the client is still connected.

You can read more about it here:

http://uk.php.net/manual/en/features...n-handling.php

Cheers,
Andy
--
Andy Jeffries MBCS CITP ZCE CMDEV
Zend Certified Engineer
Certified MySQL Developer
gPHPEdit Lead Developer - http://www.gphpedit.org

Feb 15 '07 #2

P: n/a
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!
Feb 15 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.