Re: [PHP] IE can't download, FF can: SSL ? Need special headers?
Dee Ayy wrote: Andrea and Ashley, Thanks ladies. Originally, IE claimed that the server wasn't even there (with that wacky IE error). I was lacking headers (which was fine for 6 years prior). The code below is consistent across the 3 browsers I tried (Safari, FF, IE). However, it converts spaces to underscores. I'm keeping this code: header('Content-Description: File Transfer'); header('Content-Type: '.$type); header('Content-Disposition: attachment; filename='.basename(str_replace(' ', '_', $name))); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: '.$size); echo $data; If I use header('Content-Disposition: attachment; filename='.basename($name).''); of the 3 browsers tested, only IE will replace spaces with underscores. Safari and FF pass through correctly. But I'll go with consistency and avoid the if browser-war clauses. Thanks all. This is what I'm doing: header(Pragma: public); header(Expires: 0); header(Cache-Control: must-revalidate, post-check=0, pre-check=0); header(Cache-Control: private,false); header('Content-type: application/gpx+xml'); header(Content-Disposition: attachment; filename=\Records.gpx\); header(Content-Transfer-Encoding: binary); print $myxml-saveXML(); -=- Looks very similar to yours, but I haven't tested in IE or Safari. I got the headers to send from some php cookbook website. Technically the mime type I'm sending in my case isn't valid (there is not an official gpx mime type), but it works and allows association with a helper application specific to gpx files. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] IE can't download, FF can: SSL ? Need special headers?
On 22 May 2009 20:41, Dee Ayy advised: That's what I had in my first post. What are the rest of your headers? This is what is now deployed and I consider this issue resolved, but allowing spaces in the filename across IE, FF, and Safari browsers would be the real solution. Haven't tried this, but does URL encoding spaces with %20 rather than + help any? If so, you might want to consider using rawurlencode(). It's untested on other browsers: header('Content-Description: File Transfer'); header('Content-Type: '.$type); header('Content-Disposition: attachment; filename='.basename(str_replace(' ', '_', $name))); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: '.$size); echo $data; Cheers! Mike -- Mike Ford, Electronic Information Developer, C507, Leeds Metropolitan University, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] IE can't download, FF can: SSL ? Need special headers?
Ashley, Don't scare me like that. I know I'm losing my eye sight, but a copy-paste-diff shows your header(Content-Disposition: attachment; filename=\$filename\); differs from my original post's header(Content-Disposition: attachment; filename=\$name\); by only the text file. This method (with the other headers I used in my original post) fails on IE with the lame error: Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later. Hence the reason for my post in the first place. If you would show your other headers for the \ quoted method, I'd be happy to test them. Maybe you were comparing your method to my single tick method? Mike, rawurlencode (sounded promising) but did in fact leave it saved on the hard drive as %20 rather than + or the desired space. I find the str_replace spaces to underscores more readable, although saving to the hard drive with spaces would be best. Thanks though. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] IE can't download, FF can: SSL ? Need special headers?
On Tue, 2009-05-26 at 10:09 -0500, Dee Ayy wrote: Ashley, Don't scare me like that. I know I'm losing my eye sight, but a copy-paste-diff shows your header(Content-Disposition: attachment; filename=\$filename\); differs from my original post's header(Content-Disposition: attachment; filename=\$name\); by only the text file. This method (with the other headers I used in my original post) fails on IE with the lame error: Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later. Hence the reason for my post in the first place. If you would show your other headers for the \ quoted method, I'd be happy to test them. Maybe you were comparing your method to my single tick method? Mike, rawurlencode (sounded promising) but did in fact leave it saved on the hard drive as %20 rather than + or the desired space. I find the str_replace spaces to underscores more readable, although saving to the hard drive with spaces would be best. Thanks though. Sorry, i could have sworn it wasn't there, but I was probably looking at a different thread. Just to recap, was it just the name of the file that didn't carry across properly, or did the file not save at all? Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] IE can't download, FF can: SSL ? Need special headers?
The following code has been working for about 6 years. The only change I am aware of is that now it is being served from a server requiring SSL to access it. header(Content-type: $type); header(Content-length: $size); header(Content-Disposition: attachment; filename=\$name\); echo $data; It still works in FF, so I assume the variables are being filled in. For example: header(Content-type: application/pdf); header(Content-length: 75485); header(Content-Disposition: attachment; filename=\test.pdf\); In DebugBar HTTP(S) after the GET request which had to be authorized by htaccess it reports: HTTP/1.1 200 OK Date: Fri, 22 May 2009 14:38:18 GMT Server: Apache/2.0.50 (Fedora) X-Powered-By: PHP/5.1.6 Set-Cookie: PHPSESSID=743ba4d8e056873c4da52b123df4b1ad; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Content-length: 7359 Content-Disposition: attachment; filename=test.pdf Connection: close Content-Type: application/pdf Should HTTP/1.1 200 OK be HTTPS/1.1 200 OK? If so, how can I get that set? Is there some funky header I need? Oh, the IE 7 error is: Internet Explorer cannot download my_php_file.php?a_name=a_value from my.site.com. Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later. FYI: If the user cannot choose a filename to save as, it gets saved as my_php_file.php which needs to be renamed to extension .pdf to be viewed in a PDF viewer. So if you have any helpful headers to force the filename, I'd appreciate that too. Apparently Content-Disposition: attachment; filename=test.pdf doesn't work (on FF and maybe other browsers). There is an issue with Internet Explorer 6 http://support.microsoft.com/?kbid=816037 that seems to relate, but this is for IE 7, and I can't verify if it is also failing on IE 6. But I found this (which didn't work for me) http://www.vistaheads.com/forums/microsoft-public-internetexplorer-general/313324-downloading-ftp-files-ie7.html Regards. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] IE can't download, FF can: SSL ? Need special headers?
SSL occurs a layer above HTTP, so HTTP/1.1 is correct. HTTPS is not a different data protocol, but a different transport protocol. HTH, Kyle -Original Message- From: Dee Ayy [mailto:dee@gmail.com] Sent: Friday, May 22, 2009 11:05 AM To: php-general@lists.php.net Subject: [PHP] IE can't download, FF can: SSL ? Need special headers? The following code has been working for about 6 years. The only change I am aware of is that now it is being served from a server requiring SSL to access it. header(Content-type: $type); header(Content-length: $size); header(Content-Disposition: attachment; filename=\$name\); echo $data; It still works in FF, so I assume the variables are being filled in. For example: header(Content-type: application/pdf); header(Content-length: 75485); header(Content-Disposition: attachment; filename=\test.pdf\); In DebugBar HTTP(S) after the GET request which had to be authorized by htaccess it reports: HTTP/1.1 200 OK Date: Fri, 22 May 2009 14:38:18 GMT Server: Apache/2.0.50 (Fedora) X-Powered-By: PHP/5.1.6 Set-Cookie: PHPSESSID=743ba4d8e056873c4da52b123df4b1ad; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Content-length: 7359 Content-Disposition: attachment; filename=test.pdf Connection: close Content-Type: application/pdf Should HTTP/1.1 200 OK be HTTPS/1.1 200 OK? If so, how can I get that set? Is there some funky header I need? Oh, the IE 7 error is: Internet Explorer cannot download my_php_file.php?a_name=a_value from my.site.com. Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later. FYI: If the user cannot choose a filename to save as, it gets saved as my_php_file.php which needs to be renamed to extension .pdf to be viewed in a PDF viewer. So if you have any helpful headers to force the filename, I'd appreciate that too. Apparently Content-Disposition: attachment; filename=test.pdf doesn't work (on FF and maybe other browsers). There is an issue with Internet Explorer 6 http://support.microsoft.com/?kbid=816037 that seems to relate, but this is for IE 7, and I can't verify if it is also failing on IE 6. But I found this (which didn't work for me) http://www.vistaheads.com/forums/microsoft-public-internetexplorer-gener al/313324-downloading-ftp-files-ie7.html Regards. -- 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] IE can't download, FF can: SSL ? Need special headers?
On Fri, May 22, 2009 at 11:07 AM, kyle.smith kyle.sm...@inforonics.comwrote: SSL occurs a layer above HTTP, so HTTP/1.1 is correct. HTTPS is not a different data protocol, but a different transport protocol. HTH, Kyle -Original Message- From: Dee Ayy [mailto:dee@gmail.com] Sent: Friday, May 22, 2009 11:05 AM To: php-general@lists.php.net Subject: [PHP] IE can't download, FF can: SSL ? Need special headers? The following code has been working for about 6 years. The only change I am aware of is that now it is being served from a server requiring SSL to access it. header(Content-type: $type); header(Content-length: $size); header(Content-Disposition: attachment; filename=\$name\); echo $data; It still works in FF, so I assume the variables are being filled in. For example: header(Content-type: application/pdf); header(Content-length: 75485); header(Content-Disposition: attachment; filename=\test.pdf\); In DebugBar HTTP(S) after the GET request which had to be authorized by htaccess it reports: HTTP/1.1 200 OK Date: Fri, 22 May 2009 14:38:18 GMT Server: Apache/2.0.50 (Fedora) X-Powered-By: PHP/5.1.6 Set-Cookie: PHPSESSID=743ba4d8e056873c4da52b123df4b1ad; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Content-length: 7359 Content-Disposition: attachment; filename=test.pdf Connection: close Content-Type: application/pdf Should HTTP/1.1 200 OK be HTTPS/1.1 200 OK? If so, how can I get that set? Is there some funky header I need? Oh, the IE 7 error is: Internet Explorer cannot download my_php_file.php?a_name=a_value from my.site.com. Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later. FYI: If the user cannot choose a filename to save as, it gets saved as my_php_file.php which needs to be renamed to extension .pdf to be viewed in a PDF viewer. So if you have any helpful headers to force the filename, I'd appreciate that too. Apparently Content-Disposition: attachment; filename=test.pdf doesn't work (on FF and maybe other browsers). There is an issue with Internet Explorer 6 http://support.microsoft.com/?kbid=816037 that seems to relate, but this is for IE 7, and I can't verify if it is also failing on IE 6. But I found this (which didn't work for me) http://www.vistaheads.com/forums/microsoft-public-internetexplorer-gener al/313324-downloading-ftp-files-ie7.htmlhttp://www.vistaheads.com/forums/microsoft-public-internetexplorer-gener%0Aal/313324-downloading-ftp-files-ie7.html Regards. -- 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 I have had the same issue with IE. What I did was save the file to the hard disk and then attempt the download. That has worked well. -- Bastien Cat, the other other white meat
Re: [PHP] IE can't download, FF can: SSL ? Need special headers?
Kyle, Well I guess that is good news. But I don't trust these headers since the filename is not being set. But that was even before this IE issue. Bastien, I don't understand how I could save the file to the hard disk from IE. But yes, I save the file (it gets saved as my_php_file.php on the hard disk when using FF) which I then rename to my_php_file.pdf, and then I open that in a PDF viewer. But IE claims that the site is either unavailable or cannot be found. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] IE can't download, FF can: SSL ? Need special headers?
On Fri, May 22, 2009 at 11:04 AM, Dee Ayy dee@gmail.com wrote: The following code has been working for about 6 years. The only change I am aware of is that now it is being served from a server requiring SSL to access it. header(Content-type: $type); header(Content-length: $size); header(Content-Disposition: attachment; filename=\$name\); echo $data; It still works in FF, so I assume the variables are being filled in. For example: header(Content-type: application/pdf); header(Content-length: 75485); header(Content-Disposition: attachment; filename=\test.pdf\); In DebugBar HTTP(S) after the GET request which had to be authorized by htaccess it reports: HTTP/1.1 200 OK Date: Fri, 22 May 2009 14:38:18 GMT Server: Apache/2.0.50 (Fedora) X-Powered-By: PHP/5.1.6 Set-Cookie: PHPSESSID=743ba4d8e056873c4da52b123df4b1ad; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Content-length: 7359 Content-Disposition: attachment; filename=test.pdf Connection: close Content-Type: application/pdf Should HTTP/1.1 200 OK be HTTPS/1.1 200 OK? If so, how can I get that set? Is there some funky header I need? Oh, the IE 7 error is: Internet Explorer cannot download my_php_file.php?a_name=a_value from my.site.com. Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later. FYI: If the user cannot choose a filename to save as, it gets saved as my_php_file.php which needs to be renamed to extension .pdf to be viewed in a PDF viewer. So if you have any helpful headers to force the filename, I'd appreciate that too. Apparently Content-Disposition: attachment; filename=test.pdf doesn't work (on FF and maybe other browsers). There is an issue with Internet Explorer 6 http://support.microsoft.com/?kbid=816037 that seems to relate, but this is for IE 7, and I can't verify if it is also failing on IE 6. But I found this (which didn't work for me) http://www.vistaheads.com/forums/microsoft-public-internetexplorer-general/313324-downloading-ftp-files-ie7.html Regards. I'm not sure about IE7 specifically, but IE is touchy about downloading documents - especially PDFs. Here are a few things I keep in mind that have worked so far: For all browsers, we send the following headers (which you appear to be setting): - Content-Type with the correct MIME type - Content-Disposition as attachment with the file name. I have found that the filename should be urlencoded to prevent problems with the file name not being recognized by the browser. - Content-Length - Content-Transfer-Encoding: binary For MSIE, identified by user-agent* we also add cache control since IE has a problem handling PDF documents when the headers direct it to not cache the document: - Expires: date('r', strtotime('+3 hours')) - Cache-Control: max-age=60 - Pragma: public * Yes, I know user-agent isn't very reliable, but generally it won't hurt other browsers if these headers are added to someone who happens to be spoofing IE. This has worked pretty well for us so far, and these are being served via SSL. (Not that they need to be, since they are just blank forms, but it prevents warnings since the rest of the site is SSL.) From what I can tell, IE has a problem with PDFs that are not cached. It seems that to handle the documents, it saves a copy in the temp folder and then directs Adobe to open that file when it spawns the reader. When you tell IE not to cache the document, it dutifully obliges, but it still tells Adobe to open the file from the temp folder. At least, that's what it looks like it tries to do. To get around the filename problems, you could also use some sort of mod_rewrite where the URL requested is the actual PDF name but let PHP handle the request if the above doesn't work for you. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] IE can't download, FF can: SSL ? Need special headers?
On Fri, May 22, 2009 at 11:21 AM, Dee Ayy dee@gmail.com wrote: Kyle, Well I guess that is good news. But I don't trust these headers since the filename is not being set. But that was even before this IE issue. Bastien, I don't understand how I could save the file to the hard disk from IE. But yes, I save the file (it gets saved as my_php_file.php on the hard disk when using FF) which I then rename to my_php_file.pdf, and then I open that in a PDF viewer. But IE claims that the site is either unavailable or cannot be found. Why are you saving the file first as PHP and then renaming to PDF? Below is the code that I use (which uses the DOMPDF class from digitaljunkies.ca ?php /* createPDF creates a pdf and streams it to the user if FF / O / S or saves it and forces a download if IE $html - the html page used to create the content $thisFileName - is the name of the file to be saved $hash - hash of the user to use as the path to the save the file to */ function createPDF($html,$thisFileName,$hash) { require_once(includes/dompdf_config.inc.php); // Turn off all error reporting //error_reporting(0); $dompdf = new DOMPDF(); $dompdf-load_html($html); $dompdf-render(); // The next call will store the entire PDF as a string in $pdf $pdf = $dompdf-output(); // You can now write $pdf to disk, store it in a database or stream it // to the client. //check if IE,since it doesn't like the stream, so we save it to disk and then stream the saved file $browserCheck = browserDetection(); if ($browserCheck) { if (!is_dir(../data/$hash)) { mkdir(../data/$hash); } // end is_dir check // save the file if(!file_put_contents(../data/$hash/$thisFileName, $pdf)) { echo failed to write new pdf file; } // output to the browser showPDF(../data/$hash/$thisFileName); }else{ $dompdf-stream($thisFileName); }// if user agent }//end function createPDF function browserDetection() { $UA = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $SF = strstr($UA, 'Safari') ? true : false; $OP = strstr($UA, 'Opera') ? true : false; $OPV = $OP ? preg_split('/opera\//i', $UA) : false; $OPV = $OPV ? floatval($OPV[1]) : false; $FF = !$OP strstr($UA, 'Firefox') ? true : false; $FFV = $FF ? preg_split('/firefox\//i', $UA) : false; $FFV = $FFV ? floatval($FFV[1]) : false; $IE = !$OP !$FF strstr($UA, 'MSIE') ? true : false; $IEV = $IE ? preg_split('/msie/i', $UA) : false; $IEV = $IEV ? floatval($IEV[1]) : false; if ($IE){ return true; }else{ return false; } }//end function broswerDetection function showPDF($file) { $name = basename($file); header(Cache-Control: maxage=1); //In seconds header(Pragma: public); // We'll be outputting a PDF header('Content-type: application/pdf'); // It will be called $name.pdf header('Content-Disposition: attachment; filename=$name'); // The PDF source is in original.pdf readfile($file); }//end function showPDF ? -- Bastien Cat, the other other white meat
Re: [PHP] IE can't download, FF can: SSL ? Need special headers?
I went with this, modified from http://php.he.net/readfile docs example 1: header('Content-Description: File Transfer'); header('Content-Type: '.$type); header('Content-Disposition: attachment; filename='.basename($name)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: '.$size); echo $data; And it works in FF 3.0.10 and IE 7 and Safari 3.2.1. I thought it would be some header magic. Bastien, I think because I was not urlencoding or not basenaming the filename, it would come through as the name of the script if the name had a space in it. test.pdf actually came through with the name test.pdf. But the real filenames are like QUOTE Part 1-2 Prospect Name.pdf. Thanks everybody. I was looking up those other header names and case sensitivity when I found the readfile example. DebugBar reports a different case than what I sent, so I thought that could be an issue too (like Content-Length versus Content-length). Moot for me now though. Re-RTFM I guess. Regards. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] IE can't download, FF can: SSL ? Need special headers?
Acceptable results, but could be better. basename works correctly for only Safari (filenames with spaces are correct). FF truncates the name starting with the first space. IE puts an underscore in place of a space. urlencode puts a plus sign in place of a space for all 3 browsers. But I've always had a note telling the user to rename the file to something useful, so I'll keep basename and not check the agent. Thoughts? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] IE can't download, FF can: SSL ? Need special headers?
On Fri, May 22, 2009 at 1:36 PM, Dee Ayy dee@gmail.com wrote: Acceptable results, but could be better. basename works correctly for only Safari (filenames with spaces are correct). FF truncates the name starting with the first space. IE puts an underscore in place of a space. urlencode puts a plus sign in place of a space for all 3 browsers. But I've always had a note telling the user to rename the file to something useful, so I'll keep basename and not check the agent. Thoughts? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php what about just CamelCasing the name? no spaces. -- Bastien Cat, the other other white meat
Re: [PHP] IE can't download, FF can: SSL ? Need special headers?
or even just str_replace(' ' , '_', $name) consistent and works, no? On Fri, May 22, 2009 at 2:21 PM, Bastien Koert phps...@gmail.com wrote: On Fri, May 22, 2009 at 1:36 PM, Dee Ayy dee@gmail.com wrote: Acceptable results, but could be better. basename works correctly for only Safari (filenames with spaces are correct). FF truncates the name starting with the first space. IE puts an underscore in place of a space. urlencode puts a plus sign in place of a space for all 3 browsers. But I've always had a note telling the user to rename the file to something useful, so I'll keep basename and not check the agent. Thoughts? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php what about just CamelCasing the name? no spaces. -- Bastien Cat, the other other white meat
Re: [PHP] IE can't download, FF can: SSL ? Need special headers?
On Fri, May 22, 2009 at 1:24 PM, Eddie Drapkin oorza...@gmail.com wrote: or even just str_replace(' ' , '_', $name) consistent and works, no? Good one. Put it back on me rather than the browser developers. But that's in line with my requesting the user to use underscores. I'll implement this str_replace. Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] IE can't download, FF can: SSL ? Need special headers?
On Fri, 2009-05-22 at 13:26 -0500, Dee Ayy wrote: Thoughts? -- what about just CamelCasing the name? no spaces. -- Bastien I've asked the user to use underscores, but they really shouldn't have to. Safari gets it right. I've found that header(Content-Disposition: attachment; filename=\$filename\); seems to work for me note, that's untested as i wrote it there, but i had a similar problem at work and found that enclosing the filename in double quotes worked for all the browsers i tested on. Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php