Hi there... I've got a Flash mp3 player on my site that I've added a "download" button to. The problem is, if they are using IE and Windows Media Player, then instead of downloading the mp3, it starts playing it. So I'm trying to mimic the action of a user clicking "Save Target As..." so that it immediately asks them where to save the file.
Now... I can't tell the user to click on "Save Target As..." because this is a Flash button, so there is no right-clicking that they can do... so I'm trying to do this using php. This is what I have at the moment that I've gotten from around the net.
<?php
//Set this to the base of where files
//can be downloaded from for security measures.
$basedir = "";
if(!$GET['file']) {
print "Sorry that file does not exist";
exit;
}
elseif(!file_exists($basedir.$GET['file'])) {
print "Sorry that file does not exist";
exit;
}
else {
$file = $basedir.$_GET['file'];
header("Content-Type: application/octet-stream");
header("Content-Length: " . filesize($file));
header("Content-Disposition: attachment; filename=\"$file\"");
echo file_get_contents($file);
}
?>
In Firefox, this works fine... but in IE, the first time you click, it says "to protect your security, Internet Explorer has stopped this site from downloading files to your computer." (obviously, I don't want to force a download, I just want to force the initiation of a download). So if you right click on that message and hit "Download File..." (to allow the file download), it does nothing (the screen flashes and then you're right back at the same page). Then, if you click the same button again, it finally opens a prompt for a "save as" download, but the filename is wrong (it's the name of the php file, instead of the actual file to be downloaded), but the file being downloaded really is the mp3 you clicked on.
Anyway... at the moment, it's a mess in IE, so I'm trying to find a better bit of code to do this so that I don't have so many problems between browsers.... has anyone found a way to do this successfully?
WATYF