Forum Moderators: coopster

Message Too Old, No Replies

gzip file for download

         

DrDoc

8:51 pm on Mar 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a script that generates a fairly large file (14Mb).
At the end of the file I do this:

$MIME = "application/x-gzip";
$file = gzencode($file,9);
$filename = "whatever.txt.gz";

header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: $MIME");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . strlen($file));

echo $file;

...but it refuses to work. First of all, it doesn't suggest the correct file name when saving. And, sometimes the download just fails entirely.

mipapage

2:51 pm on Mar 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I take it that is supposed to zip up the output that you'll be saving...?

DrDoc

7:09 pm on Mar 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yep... which it does properly and correctly in Opera and Mozilla, but not in IE.
Opera/Mozilla create the .gz file, which is properly gzipped the way it should. IE sometimes complains about downloading the file at all. Sometimes it doesn't even prompt me to save/open, but opens the compressed data in the browser.

mipapage

7:31 pm on Mar 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you behind a firewall of some sort? Sometimes AVs or firewalls munge 'content-accept', or something like that, for me. I suppose that would affect all of the browsers, but maybe you could check your accept-headers in IE vs. the others and see whats up?

DrDoc

8:12 pm on Mar 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The Content-Disposition: attachment part should still force the dialog to appear, right?

mipapage

8:21 pm on Mar 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ahh, I'm reaching a bit beyond my know-how on this one, so I'm not too sure. What I do know is that I have bumped into problems %like% this one and usually it had something to do with the header, and what it accepts etc.

sorry! I mean, it sounds right, but try and tell that to IE!

DrDoc

10:01 pm on Mar 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



try and tell that to IE

That's how I feel too...
Maybe if I change the MIME to just application/gzip
But that still doesn't solve the $filename issue...