Jump to content


Photo

The darned download just don't work


  • Please log in to reply
16 replies to this topic

#1 aahh

aahh
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 20 July 2006 - 07:59 PM

Summary: File download script works in FF but not IE. On an alternate server it works fine with IE.

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:

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.


This has nothing to do with PDF or SSL.

I've tried every conceivable code combination, here's the latest stab:

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

?>



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 by the script name, not the supplied filename. I don't think IE is even getting the headers! I tried using flush() after the headers (before "readfile()") but to no effect.

What kind of configuration issue might be causing this?





#2 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 20 July 2006 - 08:07 PM

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!
"Syntax error" .. WHERE THE **** IS IT?!

#3 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 20 July 2006 - 08:09 PM

try these settings in apache
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

Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#4 aahh

aahh
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 20 July 2006 - 09:06 PM

try these settings in apache


Thanks but no effect.



#5 aahh

aahh
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 20 July 2006 - 09:08 PM

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!


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.

#6 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 20 July 2006 - 09:15 PM

You dont need to force a zip download ok

echo"<a herf='filename.zip'>download me</a>";

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 ........................
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#7 aahh

aahh
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 20 July 2006 - 09:31 PM


You dont need to force a zip download ok


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:

<a href="http://mydomain/downloadtest.php">Download test</a>

It works when clicked. However, if I paste the url  http://mydomain/downloadtest.php directly in the browser window it fails.

Links opened from other applications (such as links opened from Outlook) naturally fail.

Any ideas?



#8 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 20 July 2006 - 09:46 PM

You use my example for zip's only.

You use the code you posted for all other file exstentions ok.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#9 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 20 July 2006 - 10:04 PM

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
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#10 aahh

aahh
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 20 July 2006 - 10:12 PM

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:

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


#11 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 20 July 2006 - 10:15 PM

wait... where does that semicolon after filename comes from??
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#12 aahh

aahh
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 20 July 2006 - 10:43 PM

wait... where does that semicolon after filename comes from??


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.

#13 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 20 July 2006 - 10:45 PM

have you tried to just remove the semicolon there, after $filename?
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#14 aahh

aahh
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 20 July 2006 - 10:49 PM

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.

#15 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 20 July 2006 - 10:54 PM

done some searching, someone posted this on php.net
header("HTTP/1.1 200 OK");
and/or
header("Status: 200 OK");

might help...
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#16 aahh

aahh
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 20 July 2006 - 11:32 PM

header("HTTP/1.1 200 OK"); etc.

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.

#17 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 20 July 2006 - 11:46 PM

have you tried to take out the caching?? i had it working with only the Content-Type, Content-Disposition, and Content-Length.

Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users