note 32112 modified in function.fread by aidan
| From: | aidan@php.net | Date: | Thu, 01 Jul 2004 08:45:18 +0000 |
| Subject: | note 32112 modified in function.fread by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72240@lists.php.net to get a copy of this message | ||
Two quick notes on download prompting...
First, the following line:
<?php
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:
<?php
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();
}
}
?>
--was--
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://php.net/manual/en/function.fread.php