I'm trying to force the browser to download an *.mp3 file on the server and I've got the 'Save to your computer' dialog box to come up but when I choose 'Save' it doesn't download the file correctly. It takes literally 1 second and the file is incomplete.
Here's what I've got:
<?
// http://www.mydomain.com/download.php?type=song&track=01
switch($type){
case "song":
switch($track){
case "01":
$file = "Awake%20-%20Everything%20For%20You.mp3";
$path = "http://www.mydomain.com/audio/Awake%20-%20Everything%20For%20You.mp3";
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: " . filetype($path));
header("Content-Length: " . filesize($path));
readfile("$path");
break;
case "02":
$file = "Awake%20-%20Second%20Place.mp3";
$path = "http://www.mydomain.com/audio/Awake%20-%20Second%20Place.mp3.mp3";
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: " . filetype($path));
header("Content-Length: " . filesize($path));
readfile("$path");
break;
}
break;
}
?>