Jump to content

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?



Link to comment
https://forums.phpfreaks.com/topic/15189-the-darned-download-just-dont-work/
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]
[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.
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 ........................

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

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
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]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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.