I have been asked to create a php 5 script that will download a mp3 file and ask the user where to save it. This script is not working: the browser spends a long time before displaying "Waiting for file ....". Finally the browser displays a message saying that it cannot display the page. Here is the code I have been using:
<?php
$file = 'Oregon-AM.mp3';
$mime_type = "audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3";
if(file_exists($file)){
header('Content-type: {$mime_type}');
header('Content-length: ' . filesize($file));
header('Content-Disposition: filename="' . $filename);
header('X-Pad: avoid browser bug');
header('Cache-Control: no-cache');
readfile($file);
}else{
header("HTTP/1.0 404 Not Found");
}
?>
Suggestions are welcomed...
Todd