Author
|
Message
|
AMX Mod X Beta Tester
Join Date: Jan 2006
Location: IA, USA
|
01-02-2007
, 16:05
[REQ] attachment.php filename header
|
#1
|
http://www.vbulletin.com/forum/archi...p/t-29110.html says...
Quote:
I found this, thought it might be of use.
From [email protected] at php.net
http://www.php.net/manual/en/function.header.php
There has been a lot of posts saying different things about using
header("Content-Disposition: attachment; filename=yourfilename");
to download files in both Netscape and IE. So I did a a bit of testing and here are my conclusive results:
Netscape works, with the correct filename in the download dialog, only if you DO have the 'attachment;' keyword, like so:
header("Content-Disposition: attachment; filename=yourfilename");
Because of a known bug, which you can read about at http://support.microsoft.com/support.../Q281/1/19.ASP, IE only downloads, with the correct filename in the download dialog, if you DO NOT have the 'attachment;' keyword, like so:
header("Content-Disposition: filename=yourfilename");
Since you do not want to inconvience one half of users or the other, you need to be able to do both. There are 2 methods to do this.
-- First Method (For quick and sleazy hackers):
header("Content-Disposition: atachment; filename=yourfilename");
Note the one 't' in attachment. This bug, but it works on BOTH browsers. I recommed you do NOT use this method, as it is very bad practice for your code to depend on a bug. If it gets fixed, like it should be, your code is now broken.
-- Second Method (For responsible code monkeys)
Detect the browser, and add attachment accordingly. Since IE is the only one with the bug, that I know of, just isolate it, like so:
if (strstr($HTTP_USER_AGENT,"MSIE"))
$attachment="";
else
$attachment=" attachment;";
header("Content-Disposition:$attachment filename=yourfilename");
|
My reason: right-click + save-as for links via attachment.php are named attachment.php.
It would be nice if this was handled better by attachment.php by sending the appropriate header signifying the target filename.
|
|
|
|