note 32112 added to function.fread
| From: | Brian at rack1 dot php dot net | Date: | Sat, 17 May 2003 07:10:49 +0000 |
| Subject: | note 32112 added to function.fread | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-48135@lists.php.net to get a copy of this message | ||
Two quick notes on download prompting...
First, the following line:
header("Cache-Control: no-cache, must-revalidate");
causes IE6 to prompt you to download the script instead of the output and will fail to connect.
Take out that header and everything works perfectly. Pragma: no-cache doesn't cause a problem.
Second, Mozilla tries to add .php to the download file name if content-type is application.
Changing the content type to the more specific MIME type (such as audio/mpeg) fixes that but causes
IE to try its plugins (such as Quicktime). The fix I found for that to specify attachment instead
of inline. Here's my code a prompted, small buffer MP3 download:
function downloadMP3 ($fileDir, $fileName) {
$completeFilePath=$fileDir.'/'.$fileName;
header('Pragma: no-cache');
header("Content-type: audio/mpeg\nContent-Disposition: attachment; filename=\"" .
$fileName . "\"\nContent-length: ".(string)(filesize($completeFilePath)));
$fd=fopen($completeFilePath,'rb');
while(!feof($fd)) {
print(fread($fd, 4096));
flush();
}
}
--
http://www.php.net/manual/en/function.fread.php
http://master.php.net/manage/user-notes.php?action=edit+32112
http://master.php.net/manage/user-notes.php?action=delete+32112
http://master.php.net/manage/user-notes.php?action=reject+32112