note 56748 added to function.header
| From: | webmaster at bandliste dot de | Date: | Wed, 14 Sep 2005 09:39:09 +0000 |
| Subject: | note 56748 added to function.header | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-95154@lists.php.net to get a copy of this message | ||
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 ...
----
Manual Page -- http://www.php.net/manual/en/function.header.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56748
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56748&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56748&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56748&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56748&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56748&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56748&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56748&report=yes
Search -- http://master.php.net/manage/user-notes.php