note 12650 deleted from function.header by jimw

From: Date: Wed, 31 Oct 2001 22:02:24 +0000
Subject: note 12650 deleted from function.header by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-19778@lists.php.net to get a copy of this message
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/kb/articles/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"); Happy coding.

« previous php.notes (#19778) next »