Tracking download completion

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • andrew.zahra@gmail.com

    Tracking download completion

    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.

  • Andy Jeffries

    #2
    Re: Tracking download completion

    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_abor ted() to see if the client is still connected.

    You can read more about it here:



    Cheers,


    Andy


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

    Comment

    • Toby A Inkster

      #3
      Re: Tracking download completion

      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_attem pts'][] = 'myvid';

      header("Content-Type: video/mpeg");
      print file_get_conten ts("myvid.mpeg" );

      if (!connection_ab orted())
      $_SESSION['download_succe sses'][] = '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('myvi d', $_SESSION['download_attem pts']))
      {
      if (in_array('myvi d', $_SESSION['download_succe sses']))
      {
      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!

      Comment

      Working...