note 60711 deleted from function.fread by googleguy

From: Date: Tue, 22 Oct 2013 14:55:15 +0000
Subject: note 60711 deleted from function.fread by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-197236@lists.php.net to get a copy of this message
Note Submitter: junk at gieson dot com ---- To force download an mp3 file and/or prevent the mp3 from ending up in the browser's cache. This is very similiar to mindplay's example below. <?php @ob_end_clean(); // Only allow mp3 files $allowedFileType = "mp3"; // Set the filename based on the URL's query string $theFile = $_REQUEST['theFile']; // Get info about the file $f = pathinfo($theFile); // Check the extension against allowed file types if(strtolower($f['extension']) != strtolower($allowedFileType)) exit; // Make sure the file exists if (!file_exists($theFile)) exit; // Set headers header("Pragma: public"); header("Expires: Thu, 19 Nov 1981 08:52:00 GMT"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: private"); header("Content-Transfer-Encoding: binary"); header("Content-Type: audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3"); // This line causes the browser's "save as" dialog header( 'Content-Disposition: attachment; filename="'.$f['basename'].'"' ); // Length required for Internet Explorer header("Content-Length: ".@urldecode(@filesize($theFile))); // Open file if (($f = fopen($theFile, 'rb')) === false) exit; // Push file while (!feof($f)) { echo fread($f, (1*(1024*1024))); flush(); @ob_flush(); } // Close file fclose($f); exit; ?>

« previous php.notes (#197236) next »