walter1917 Posted June 4, 2010 Share Posted June 4, 2010 Hi all, I am trying to serve a small text file to my users with a download. I need a flag to use to detect whether or not the file was downloaded fully or crashed/aborted before. Here's the code I've found from working on other sites. Currently, it allows for download. But I see neither the first echo 'Welcome' nor any of the other echos (Success/Fail). What is going on here? Thanks! function sendTest() { $res = null; $res = sendFile('testimage.gif', 'image/gif'); if ($res['status']) { // Download succeeded echo "Success!"; } else { // Download failed echo "Fail!"; } return; } function sendFile($path, $contentType = 'image/gif') { ignore_user_abort(true); header('Content-Description: File Transfer'); header('Content-Transfer-Encoding: binary'); header('Content-Disposition: attachment; filename="' .basename($path). "\";"); header("Content-Type: $contentType"); header('Expires: 0'); header('Cache-Control: public, must-revalidate, max-age=0'); // 1 hour $res = array('status' =>true, 'errors' =>array(), 'readfileStatus' =>null, 'aborted' =>false); ob_clean(); flush(); $res['readfileStatus'] = readfile($path); if ($res['readfileStatus'] == false) { $res['errors'][] = 'readfile failed.'; $res['status'] = false; } if (connection_aborted()) { $res['errors'][] = 'Connection aborted.'; $res['aborted'] = true; $res['status'] = false; } return $res; } echo "Welcome"; $res = sendTest(); echo "Done"; Quote Link to comment https://forums.phpfreaks.com/topic/203916-download-serve-and-detect-successfail/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.