aahh Posted July 20, 2006 Share Posted July 20, 2006 [b]Summary: File download script works in FF but not IE. On an alternate server it works fine with IE.[/b]Lots of people seem to have this problem but mine does not seem to resolve by changing headers:It works perfectly in FireFox, not at all in IE, I get the Error:[quote]Internet Explorer cannot download (script name) from (site)Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later.[/quote][i]This has nothing to do with PDF or SSL[/i].I've tried every conceivable code combination, here's the latest stab:[code]<?php $dir = dirname(__FILE__); chdir($dir); $file="testfile.zip"; $filesize = filesize($file); $filename = trim(basename($file)); ini_set('zlib.output_compression', 'Off'); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Vary: Accept-Encoding"); header("Content-Type: application/force-download"); header("Content-Disposition: attachment; filename=$filename;"); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".$filesize); @readfile($file); exit; ?>[/code]To complicate things, this code works perfectly well with IE on another server. Both servers are running PHP 4.4.2 and Apache (1.3.36 (Unix) works, 2.0.46 (Red Hat) fails)I tried a header sniffer (http://web-sniffer.net) but it fetches all headers correctly from both servers. Both look essentially identical. Also, notice that the error message (and the IE dialog) refer to the download [i]by the script name, not the supplied filename[/i]. [b]I don't think IE is even getting the headers![/b] I tried using flush() after the headers (before "readfile()") but to no effect.What kind of configuration issue might be causing this? Quote Link to comment https://forums.phpfreaks.com/topic/15189-the-darned-download-just-dont-work/ Share on other sites More sharing options...
legohead6 Posted July 20, 2006 Share Posted July 20, 2006 Maybe that servers screwed up..is it possible to try on a third? Cuz if it works on one then i dont think it would be a coding error! Quote Link to comment https://forums.phpfreaks.com/topic/15189-the-darned-download-just-dont-work/#findComment-61276 Share on other sites More sharing options...
ryanlwh Posted July 20, 2006 Share Posted July 20, 2006 try these settings in apache[code]BrowserMatch "Mozilla/2" nokeepaliveBrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0BrowserMatch "RealPlayer 4\.0" force-response-1.0BrowserMatch "Java/1\.0" force-response-1.0BrowserMatch "JDK/1\.0" force-response-1.0SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15189-the-darned-download-just-dont-work/#findComment-61281 Share on other sites More sharing options...
aahh Posted July 20, 2006 Author Share Posted July 20, 2006 [quote]try these settings in apache[/quote]Thanks but no effect. Quote Link to comment https://forums.phpfreaks.com/topic/15189-the-darned-download-just-dont-work/#findComment-61338 Share on other sites More sharing options...
aahh Posted July 20, 2006 Author Share Posted July 20, 2006 [quote author=legohead6 link=topic=101298.msg400717#msg400717 date=1153426036]Maybe that servers screwed up..is it possible to try on a third? Cuz if it works on one then i dont think it would be a coding error![/quote]There is no error in the code. It's some kind of freaky server setting which I need to either change or find a workaround. The question is, what kind of a setting could produce such an error? I'm a loss as to where to look. Quote Link to comment https://forums.phpfreaks.com/topic/15189-the-darned-download-just-dont-work/#findComment-61339 Share on other sites More sharing options...
redarrow Posted July 20, 2006 Share Posted July 20, 2006 You dont need to force a zip download ok[code]echo"<a herf='filename.zip'>download me</a>";[/code]Use my example tell what happens ok.The only time you need to force a download is when your downloading a single file ok.example.pdf.jpg.gifect ect ........................ Quote Link to comment https://forums.phpfreaks.com/topic/15189-the-darned-download-just-dont-work/#findComment-61342 Share on other sites More sharing options...
aahh Posted July 20, 2006 Author Share Posted July 20, 2006 [quote]You dont need to force a zip download ok[/quote] I think I do. My application (when it eventually downloads) will be feeding out MP3 files via email links. I don't want the MP3 to open in the browser, thus the forced download. Interestingly, if I name my script "downloadtest.php" and put it in an href linke like: [code] <a href="http://mydomain/downloadtest.php">Download test</a>[/code] It works when clicked. However, if I paste the url [tt]http://mydomain/downloadtest.php[/tt] directly in the browser window it fails. Links opened from other applications (such as links opened from Outlook) naturally fail. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/15189-the-darned-download-just-dont-work/#findComment-61351 Share on other sites More sharing options...
redarrow Posted July 20, 2006 Share Posted July 20, 2006 You use my example for zip's only.You use the code you posted for all other file exstentions ok. Quote Link to comment https://forums.phpfreaks.com/topic/15189-the-darned-download-just-dont-work/#findComment-61364 Share on other sites More sharing options...
ryanlwh Posted July 20, 2006 Share Posted July 20, 2006 try not to use application/force-download.. maybe application/*.. the content-disposition: attachment; header will take care of the download part. also try to put quotes around the filename. for some weird reason, IE sometimes have problem parsing the filename Quote Link to comment https://forums.phpfreaks.com/topic/15189-the-darned-download-just-dont-work/#findComment-61376 Share on other sites More sharing options...
aahh Posted July 20, 2006 Author Share Posted July 20, 2006 Even as an mp3 file and without forced download it does the same thing.Frankly, I just don't think IE is even getting the headers. Something is going wrong before that. The error message says it cannot download "script-name", not "filename".Here's the current code:[code]<?php $dir = dirname(__FILE__); chdir($dir); $file="testfile.mp3"; $filesize = filesize($file); $filename = trim(basename($file)); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Vary: Accept-Encoding"); //header("Content-Type: application/force-download"); header("Content-Type: application/*"); header("Content-Disposition: attachment; filename=\"$filename\";"); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".$filesize); @readfile($file); exit; ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15189-the-darned-download-just-dont-work/#findComment-61380 Share on other sites More sharing options...
ryanlwh Posted July 20, 2006 Share Posted July 20, 2006 wait... where does that semicolon after filename comes from?? Quote Link to comment https://forums.phpfreaks.com/topic/15189-the-darned-download-just-dont-work/#findComment-61381 Share on other sites More sharing options...
aahh Posted July 20, 2006 Author Share Posted July 20, 2006 [quote]wait... where does that semicolon after filename comes from??[/quote]Just one more variation that was tried. It makes no difference -- quotes, semicolons -- all work with FF, none work with IE (on my server).IE never even sees the filename.I'm forced to the only logical conclusion: Gremlins. Quote Link to comment https://forums.phpfreaks.com/topic/15189-the-darned-download-just-dont-work/#findComment-61398 Share on other sites More sharing options...
ryanlwh Posted July 20, 2006 Share Posted July 20, 2006 have you tried to just remove the semicolon there, after $filename? Quote Link to comment https://forums.phpfreaks.com/topic/15189-the-darned-download-just-dont-work/#findComment-61400 Share on other sites More sharing options...
aahh Posted July 20, 2006 Author Share Posted July 20, 2006 Yes, tried with and without quotes, with and without semicolon and every other combination. There's some other bug, maybe not in the code, which I need to identify and work around. Quote Link to comment https://forums.phpfreaks.com/topic/15189-the-darned-download-just-dont-work/#findComment-61405 Share on other sites More sharing options...
ryanlwh Posted July 20, 2006 Share Posted July 20, 2006 done some searching, someone posted this on php.net[code]header("HTTP/1.1 200 OK");and/orheader("Status: 200 OK");[/code]might help... Quote Link to comment https://forums.phpfreaks.com/topic/15189-the-darned-download-just-dont-work/#findComment-61408 Share on other sites More sharing options...
aahh Posted July 20, 2006 Author Share Posted July 20, 2006 [code]header("HTTP/1.1 200 OK"); etc.[/code]Yes, I saw that also but I tried it with no effect. IE just kind of hangs around on the "Getting File Information" dialog for a few seconds then gives up. Quote Link to comment https://forums.phpfreaks.com/topic/15189-the-darned-download-just-dont-work/#findComment-61432 Share on other sites More sharing options...
ryanlwh Posted July 20, 2006 Share Posted July 20, 2006 have you tried to take out the caching?? i had it working with only the Content-Type, Content-Disposition, and Content-Length. Quote Link to comment https://forums.phpfreaks.com/topic/15189-the-darned-download-just-dont-work/#findComment-61438 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.