note 56748 deleted from function.header by bjori

From: Date: Mon, 27 Mar 2006 09:46:10 +0000
Subject: note 56748 deleted from function.header by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-106709@lists.php.net to get a copy of this message
Note Submitter: webmaster at bandliste dot de ---- For some months I was looking for a working script to offer download of mp3 data from a hidden location, which works for IE also. It never worked, even not with the comments on this page. Now I figured it out myself and think, it could be interesting for anybody else: header("Pragma: public"); header("Expires: 0"); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Cache-Control: pre-check=0, post-check=0, max-age=0', false); header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT'); $browser = $_SERVER['HTTP_USER_AGENT']; if (preg_match('/MSIE 5.5/', $browser) || preg_match('/MSIE 6.0/', $browser)) { header('Pragma: private'); header('Cache-control: private, must-revalidate'); // the c in control is lowercase, didnt work for me with uppercase header("Content-Length: ".$content_len); // MUST be a number for IE header('Content-Type: audio/mpeg'); header('Content-Disposition: inline; filename="'.$dateiname.'"'); } else { header("Content-Length: ".(string)(filesize($path))); header('Content-Type: audio/mpeg'); header("Content-Disposition: inline; filename=".$dateiname.""); } header('Content-Transfer-Encoding: binary'); if ($file = fopen($path, 'rb')) { while(!feof($file) and (connection_status()==0)) { print(fread($file, 1024*8)); flush(); //usleep(100000); // can be used to limit download speed } fclose($file); } There are still problems with IE. Sometimes the content of the mp3 is displayed instead of downloaded, after pressing reload in the browser it works again. Didnt find out, whats still wrong. One more question: is it possible to change the referrer from the originating page with the header() function ? How would it work with PHP ? Thanks and hope this helps ...

« previous php.notes (#106709) next »