Page 1 of 1

headers different for IE on Macs?

Posted: Fri Aug 16, 2002 3:00 pm
by dave_mwi
The following code fairly well filters for a request to either download a file by clicking on a link, or open that file with a helper application lik PDFs and Acrobat.

Code: Select all

##Downloading
$browser_type = getenv("HTTP_USER_AGENT");
$query="select * from files where file_id = "$file_id"";
$result=mysql_query($query);
$assoc = mysql_fetch_assoc($result);
if (preg_match("/compatible; MSIE/i", "$browser_type")){
	header("Content-type: application/octetstream");
	header("Content-Disposition: attachment; filename="".$assocї"name"].""");
}
else{
	header("Content-type: application/octet-stream");
	header("Content-Disposition: attachment; filename="".$assocї"name"].""");
}
echo $assocї"file"];

##Streaming or Opening
$browser_type = getenv("HTTP_USER_AGENT");
$query="select * from files where file_id = "$file_id"";
$result=mysql_query($query);
$assoc = mysql_fetch_assoc($result);	
if (preg_match("/compatible; MSIE/i", "$browser_type")){	
	header("Content-type:".$assocї"type"]."");
	header("Content-Disposition: inline; filename="".str_replace("\.exe","",$assocї"name"]).""");
}
else{
	header("Content-type: audio/x-mp3");
	header("Content-Disposition: attachment; filename="".$assocї"name"].""");
}	
echo $assocї"file"];

And it works pretty good for IE and Mozilla or NS 6.2 for the exceiption of Mozilla & NS trying to save a downloaded file as 'filename.mp3.exe'...still haven't been able to correct that.

I am also experiencing some difficulties with Macintosh IE 5.2 which when trying to download the file tries to save it as 'index.php' instead of the filename.mp3.

I imagine I would have to to an additional check if the platform is mac, but I have no idea which headers would properly start a download to save the file to the mac filesystem with the correct name because I don't have a mac to test on. If anyone has any experience with macs and headers, or just a lot of experience with headers :D would be great.

Posted: Fri Aug 16, 2002 3:11 pm
by hob_goblin
str_replace(".exe", "" ...

no need to escape the '.' to my knowledge

Tried both

Posted: Fri Aug 16, 2002 3:45 pm
by dave_mwi
I've tried both ways...escaping and not escaping...but the thing is that NS and Mozilla add that extension automatically because in order to tell the browser to download the mp3 and not stream it, you have to use a header that describes the file as something other than mp3, in my case it is application/octet-stream. However, in IE this works fine and IE goes ahead and saves as what

header("Content-Disposition: attachment; filename=\"".$assoc["name"]."\"");

specifies it should be saved as...but NS and Moz are ignoring that it seems and determining the extension based up this header:

header("Content-type: application/octet-stream");

So I'm trying to find out a solution for that, as well as IE on a mac reacting differently also...