Jump to content

Archived

This topic is now archived and is closed to further replies.

aahh

The darned download just don't work

Recommended Posts

[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?



Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
try these settings in apache
[code]
BrowserMatch "Mozilla/2" nokeepalive
BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0
BrowserMatch "RealPlayer 4\.0" force-response-1.0
BrowserMatch "Java/1\.0" force-response-1.0
BrowserMatch "JDK/1\.0" force-response-1.0

SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown[/code]

Share this post


Link to post
Share on other sites
[quote]try these settings in apache[/quote]

Thanks but no effect.

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites
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
.gif

ect ect ........................

Share this post


Link to post
Share on other sites

[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?

Share this post


Link to post
Share on other sites
You use my example for zip's only.

You use the code you posted for all other file exstentions ok.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
wait... where does that semicolon after filename comes from??

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites
have you tried to just remove the semicolon there, after $filename?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
done some searching, someone posted this on php.net
[code]header("HTTP/1.1 200 OK");
and/or
header("Status: 200 OK");[/code]

might help...

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites
have you tried to take out the caching?? i had it working with only the Content-Type, Content-Disposition, and Content-Length.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.