title: check if download is completed
body: <p>What is the best possible way to detect if a download is completed, because afterward I want to update the database.</p>
  
  <p>I tried some of this code from the PHP manual, but it doesn't do much for me:</p>
  
  <pre><code>header("Content-Type: application/octet-stream"); 
  header("Content-Length: ".filesize($file)); 
  header("Content-Disposition: attachment; filename=$filename");
  
  // buffered read not using readfile($file);
  
  if ($fp = fopen($bestand, 'rb')) {
      while (!feof($fp)) {
          $buf = fread($fp, 4096);
          echo $buf;
          $bytesSent += strlen($buf);    /* We know how many bytes were sent to the user */
      }     
   }
  
  if ($bytesSent == filesize($fp)) {
      //do something with db
  }
  </code></pre>