Hello,
Before I begin, here is our current client setup that we are having issues with.
- Windows XP SP3
- Internet Explorer 6 SP3
We are having an issue with forcing a download of an MP3 in Internet Explorer 6 and sometimes 7. Mozilla(Firefox 2 & 3) and Safari 3.x work fine and bring up the Save As dialog box correctly.
This is what is happening. A user clicks on a button in a Flash Application to initiate a call to a file called download.php, which initiates the force download of the MP3 using the header() php functions. The Save As dialog box appears correctly, but instead of downloading the MP3, it tries to download whatever is at the end of the URL, directory name or file name. An example is if the URL is like [url]
http://www.domain.com/directory[/url], it tries to download "directory". If we type in the URL directly like [url]
http://www.domain.com/download.php[/url] it tries to download "download_php". In every other browser, it will initiate a download and download the MP3 correctly, but in IE it will not download the MP3 and will just timeout.
At the Save As dialog box, if you click on Open it tries to open in Windows Media Player, but fails because it is trying to download a file that doesn't exist. If you click Save, it times out because it is trying to download a file that doesn't exists. If you click Cancel, then click on the button in the Flash Application to initiate a call to download.php, it downloads the MP3 without any issues.
We understand there have been issues with IE with Content-Disposition since 4.0 ([url]
http://www.jtricks.com/bits/content_disposition.html[/url]),
but was wondering if anyone has come up with a solution or a workaround. Below is the code we are currently using.
if(ini_get('zlib.output_co
mpression'
)) { ini_set('zlib.output_compr
ession', 'Off'); }
// get the file mime type using the file extension
switch(strtolower(substr(s
trrchr($fi
le_name,'.
'),1)))
{
case 'pdf': $mime = 'application/pdf'; break;
case 'zip': $mime = 'application/zip'; break;
case 'jpeg':
case 'jpg': $mime = 'image/jpg'; break;
case 'mp3': $mime = 'audio/mpeg'; break;
default: $mime = 'application/force-downloa
d'; break;
}
header('Pragma: public'); // required
header('Expires: 0'); // no cache
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private',false);
//if(!ereg("MSIE 7.0",$_SERVER['HTTP_USER_A
GENT'])){
//removing the Content Type for IE 7 seems to work
header('Content-Type: '.$mime);
//}
header("Accept-Ranges: bytes");
header("Content-Dispositio
n: attachment; filename=\"".basename($fil
e_name)."\
"");
header('Content-Transfer-E
ncoding: binary');
header('Content-Length: '.filesize($file_name)); // provide file size
readfile($file_name); // push it out */
All help is welcome.
Thanks in advanced!
Start Free Trial