Raised This Month: $32 Target: $400
 8% 

[REQ] attachment.php filename header


  
 
 
Thread Tools Display Modes
Author Message
jRaven
AMX Mod X Beta Tester
Join Date: Jan 2006
Location: IA, USA
Old 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.
jRaven is offline
Send a message via ICQ to jRaven Send a message via AIM to jRaven
BAILOPAN
Join Date: Jan 2004
Old 01-02-2007 , 22:23   Re: [REQ] attachment.php filename header
#2

I am pretty sure that the reason this happens is not because of a wrong header (note the post is from 2001 so this would be fixed by now), but because you're right clicking. The browser doesn't actually fetch anything until you've accepted the file save, so it has no way of knowing the filename beforehand. Thus it simply brings up "attachment.php" and doesn't start until you've clicked OK.
__________________
egg
BAILOPAN is offline
jRaven
AMX Mod X Beta Tester
Join Date: Jan 2006
Location: IA, USA
Old 01-02-2007 , 23:32   Re: [REQ] attachment.php filename header
#3

You are correct. (Tested w/ Perl and wget headers)

It looks like Firefox/2.0.0.1 never makes a request before presenting the save-as dialog.

Sorry I didn't do my research earlier. (Honk!)
jRaven is offline
Send a message via ICQ to jRaven Send a message via AIM to jRaven
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:52.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode