======Peter's Ratchet App====== ====File Download Functionality Option 1==== PHP has a built-in function named **http_send_file** that sends a file to the browser and returns **true** for a success and **false** for a failure. * [[http://www.php.net/manual/en/function.http-send-file.php]] ====File Download Functionality Option 2==== You could create a function that sends the file in chunks and keeps track of whether the whole file was sent. function readfile_chunked ($filename) { $chunksize = 1*(1024*1024); // how many bytes per chunk $buffer = ''; $handle = fopen($filename, 'rb'); if ($handle === false) { return false; } while (!feof($handle)) { $buffer = fread($handle, $chunksize); print $buffer; ob_flush(); flush(); } // You could either count the number of chunks sent or maybe test for eof to determine if the entire file was downloaded. if (feof($handle)) // Flag the file as downloaded in the db. return fclose($handle); }