[PHP] forcing file downloads
I know this has been discussed many times, but I've been hunting through the archives with very little resolution on the issue. I've found the following note in the annotated manual: Additional notes to my workaround on Q266305: I have tested my findings with PDF, XLS, DOC and ZIP. However JPG and GIF didn't make IE pop up the download box. By changing content type from octet-stream to force-download (or some undefined type), it will work. Of course, we need to take care of other browsers too. Here is the improved code, hope it helps: header(Content-type: application/force-download); if (strstr($_SERVER[HTTP_USER_AGENT], MSIE)) header(Content-Disposition: filename=$myfile . %20); // For IE else header(Content-Disposition: attachment; filename=$myfile); // For Other browsers Note: If you are using session together with this download, you will need to add the following line BEFORE the code above to make IE work: session_cache_limiter(); 1. Is this a widely accepted practice for forcing downloads (a pop-up window to download a file), given the problems with older versions of IE? 2. Can someone tell me what the %20 is there for? Regards, Justin French -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] forcing file downloads
20% represents a space. -Jared -Original Message- From: Justin French [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 12, 2002 9:01 AM To: php Subject: [PHP] forcing file downloads I know this has been discussed many times, but I've been hunting through the archives with very little resolution on the issue. I've found the following note in the annotated manual: Additional notes to my workaround on Q266305: I have tested my findings with PDF, XLS, DOC and ZIP. However JPG and GIF didn't make IE pop up the download box. By changing content type from octet-stream to force-download (or some undefined type), it will work. Of course, we need to take care of other browsers too. Here is the improved code, hope it helps: header(Content-type: application/force-download); if (strstr($_SERVER[HTTP_USER_AGENT], MSIE)) header(Content-Disposition: filename=$myfile . %20); // For IE else header(Content-Disposition: attachment; filename=$myfile); // For Other browsers Note: If you are using session together with this download, you will need to add the following line BEFORE the code above to make IE work: session_cache_limiter(); 1. Is this a widely accepted practice for forcing downloads (a pop-up window to download a file), given the problems with older versions of IE? 2. Can someone tell me what the %20 is there for? Regards, Justin French -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] forcing file downloads
Justin French wrote: snip force code / 1. Is this a widely accepted practice for forcing downloads (a pop-up window to download a file), given the problems with older versions of IE? I believe so. Sad, really :o). Y'see, what you're doing is forcing your own preferences on the user (usually against their will) which is a Bad Thing. Also, what are you going to do if the user's got a way of handling the MIME-type that you didn't expect? They could be trying to open up force/downloads in their text editor, but *want* to have the file in question (say, a .pdf) open up somewhere else. Okay, so I spend too much time involved in web design, where the f-word is considered rude. 2. Can someone tell me what the %20 is there for? You can try typing http://www.foo.net/bar/of soap/he he he/ and it may work in some browsers. The %20 (I forget the exact explanation, sorry) is basically code for the space. All browsers understand http://www.foo.net/bar/of%20soap/he%20he%20he/ HTH -- Mark Gallagher -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] forcing file downloads
Justin French wrote: snip force code / 1. Is this a widely accepted practice for forcing downloads (a pop-up window to download a file), given the problems with older versions of IE? I believe so. Don't. 2. Can someone tell me what the %20 is there for? You can try typing http://www.foo.net/bar/of soap/he he he/ and it may work in some browsers. The %20 (I forget the exact explanation, sorry) is basically code for the space. All browsers understand http://www.foo.net/bar/of%20soap/he%20he%20he/ 20 is the hex code for a space. When the url get 'URLENCODED' any non-valid characters get converted to hex. In some (broken?) browsers a space in the URL may work but it's generally not a good idea. =C= * * Cal Evans * Techno-Mage * http://www.calevans.com * -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] forcing file downloads
2. Can someone tell me what the %20 is there for? The %20 (I forget the exact explanation, sorry) is basically code for the space. % in a URL means thats its gonna be followed by a 2 digit hex number referencing directly to the ascii table. 20 is the hex equivelant for . You could rewrite http://; as %68%74%74%70%3a%2f%2f. -- Dan Hardiker [[EMAIL PROTECTED]] ADAM Software Systems Engineer First Creative Ltd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php