By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,994 Members | 2,036 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,994 IT Pros & Developers. It's quick & easy.

Forced download issue with IE6

P: n/a
Hi folks,

I appreciate that this topic of forced downloads has been discussed in
various threads but my situtation is a little different to those that I
have come across and am experiencing a wierd issue in IE6.

Essentially I am executing a select query against a MySql database and
taking the result of that query and building a csv stream on the fly to
send to the browser as a forced download.

I have a function which has been cobbled together from a few internet
sources. Code below:

function ForceDownload ($data, $name, $filesize=false) {

if ($filesize == false OR !is_numeric($filesize)) {
$filesize = strlen($data);
}

$mimetype = 'application/force-download';

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,
pre-check=0");
header("Cache-Control: private",false);
header("Content-Transfer-Encoding: binary");
header("Content-Type: " . $mimetype);
header("Content-Length: " . $filesize);
header("Content-Disposition: attachment; filename=\"" . $name .
"\";" );

echo $data;
die();
}

I am calling it from my page like so:

$result = GetContacts($searchTerm, $searchType);
$data = '';
while($row = mysql_fetch_assoc($result)) {
$data .= $row['ContactName'] . ',' . $row['Email'];
}
ForceDownload($data, 'contactExport.csv');

This works fine in Firefox but IE6 refuses to do anything at all. It
doesn't even display the content of the stream inline (ie in the
browser window).

Any ideas greatly appreciated.

Simon

Jul 13 '06 #1
Share this Question
Share on Google+
14 Replies


P: n/a
Rik
Simon Rigby wrote:
Hi folks,

I appreciate that this topic of forced downloads has been discussed in
various threads but my situtation is a little different to those that
I have come across and am experiencing a wierd issue in IE6.

Essentially I am executing a select query against a MySql database and
taking the result of that query and building a csv stream on the fly
to send to the browser as a forced download.

I have a function which has been cobbled together from a few internet
sources. Code below:
I don't know wether it's the problem but this:
$mimetype = 'application/force-download';
header("Content-Type: " . $mimetype);
Is something that's very bad practise IMO.

This is normally enough for me:
header("Content-Disposition: attachment; filename=\"" . $name .
"\";" );
Grtz,
--
Rik Wasmus
Jul 13 '06 #2

P: n/a
I'll try that Rik. But I'm interested to know why its bad practice?

Simon

Jul 13 '06 #3

P: n/a
Hmm. Actually thats still not working. Works in Firefox still but
nothing in IE. Just a browser flash as the form posts and then nothing.
Well not striclty true. The form posts back to itself and the
underlying page is rendering correctly but no download.

Simon Rigby wrote:
I'll try that Rik. But I'm interested to know why its bad practice?

Simon
Jul 13 '06 #4

P: n/a
Simon Rigby:

[re 'application/force-download' for CSVs]
But I'm interested to know why its bad practice?
because there's already a MIME type registered for CSV, text/csv.

'application/force-download' isn't registered, and this subtype doesn't
mark its proprietariness with 'x-' - going against the MIME spec.

and content-type 'indicates the media type of the entity-body sent to
the recipient' (RFC2616: 14.17); it doesn't disposition the message.

more details in the archived discussions. HTH

--
Jock

Jul 14 '06 #5

P: n/a
Ah right, yes I understand. I was under the impression that using
anything that wouldnt be recognised by the browser was part of
"forcing" the download. I get it!

Does anyone know why this is nt working in IE6.

I have cut down the code to just apply the content disposition header.
Still workin Firefox but no joy in IE.

Simon

John Dunlop wrote:
Simon Rigby:

[re 'application/force-download' for CSVs]
But I'm interested to know why its bad practice?

because there's already a MIME type registered for CSV, text/csv.

'application/force-download' isn't registered, and this subtype doesn't
mark its proprietariness with 'x-' - going against the MIME spec.

and content-type 'indicates the media type of the entity-body sent to
the recipient' (RFC2616: 14.17); it doesn't disposition the message.

more details in the archived discussions. HTH

--
Jock
Jul 16 '06 #6

P: n/a
Simon Rigby wrote:
Ah right, yes I understand. I was under the impression that using
anything that wouldnt be recognised by the browser was part of
"forcing" the download. I get it!

Does anyone know why this is nt working in IE6.

I have cut down the code to just apply the content disposition header.
Still workin Firefox but no joy in IE.

Simon
Probably because IE is ignoring the headers and doing what it wants -
it's notorious for that.

At this point, you'll probably get better responses in alt.html. This
doesn't look like anything PHP is doing.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 16 '06 #7

P: n/a
Thanks for the pointer Jerry.

Simon

Jerry Stuckle wrote:
Simon Rigby wrote:
Ah right, yes I understand. I was under the impression that using
anything that wouldnt be recognised by the browser was part of
"forcing" the download. I get it!

Does anyone know why this is nt working in IE6.

I have cut down the code to just apply the content disposition header.
Still workin Firefox but no joy in IE.

Simon

Probably because IE is ignoring the headers and doing what it wants -
it's notorious for that.

At this point, you'll probably get better responses in alt.html. This
doesn't look like anything PHP is doing.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 16 '06 #8

P: n/a
Simon Rigby wrote:
Thanks for the pointer Jerry.

Simon

Jerry Stuckle wrote:
>Simon Rigby wrote:
>>Ah right, yes I understand. I was under the impression that using
anything that wouldnt be recognised by the browser was part of
"forcing" the download. I get it!

Does anyone know why this is nt working in IE6.

I have cut down the code to just apply the content disposition header.
Still workin Firefox but no joy in IE.

Simon
Probably because IE is ignoring the headers and doing what it wants -
it's notorious for that.

At this point, you'll probably get better responses in alt.html. This
doesn't look like anything PHP is doing.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
This happened to me once while developing a J2EE application, but I
think it will apply here as well.

Try changing value for "expires". You can try making it something like
30 minutes to start with and then if that works, lower the value to few
seconds.

What IE does, in my opinion, is that it downloads the file first to disk
cache before it opens it. But as soon as download is finished, it
realizes that the content is supposed to be expire in 0 seconds, so it
doesn't display anything.

If I am correct, it used to give file not found error in older versions.
Try it and let me know. I am curious as well.
Jul 17 '06 #9

P: n/a

Simon Rigby wrote:
Thanks for the pointer Jerry.

Simon

Jerry Stuckle wrote:
Simon Rigby wrote:
Ah right, yes I understand. I was under the impression that using
anything that wouldnt be recognised by the browser was part of
"forcing" the download. I get it!
>
Does anyone know why this is nt working in IE6.
>
I have cut down the code to just apply the content disposition header.
Still workin Firefox but no joy in IE.
>
Simon
>
Probably because IE is ignoring the headers and doing what it wants -
it's notorious for that.

At this point, you'll probably get better responses in alt.html. This
doesn't look like anything PHP is doing.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
By and large, i find force-download and saying the content type is some
sort of other format (x-octet-stream, iirc) works fairly well in IE. I
always have had the sneaking suspicion IE caches any file it recognizes
regardless of what any header says, though.

If you resolve this _please_ post how you did it - this is a problem i
always run into with IE. The solution always seems to be different,
too.

Jul 17 '06 #10

P: n/a
I appreciate the help guys but I;m still not having a lot of luck. The
main difference I find in my example from others on the web is that the
examples I have seen apply to a file that already exsists, whereas in
my case I am setting the headers and then "echoing" the $data to the
browser. Could this be why its not working in IE? I;m really scratching
my nut on this one, especially as it works fine in Firefox.

Cheers

Simon

Jul 17 '06 #11

P: n/a
Simon Rigby wrote:
I appreciate the help guys but I;m still not having a lot of luck. The
main difference I find in my example from others on the web is that the
examples I have seen apply to a file that already exsists, whereas in
my case I am setting the headers and then "echoing" the $data to the
browser. Could this be why its not working in IE? I;m really scratching
my nut on this one, especially as it works fine in Firefox.

Cheers

Simon
Simon,

Might I (again) suggest you ask in alt.html? This doesn't look like a
problem with PHP - if it were, it should act the same in both browsers.
Rather, it looks like something IE is doing differently.

And alt.html would have more experts on why IE works different than FF
with the same valid HTML.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 17 '06 #12

P: n/a
Rik
Jerry Stuckle wrote:
Simon Rigby wrote:
>I appreciate the help guys but I;m still not having a lot of luck.
The main difference I find in my example from others on the web is
that the examples I have seen apply to a file that already exsists,
whereas in my case I am setting the headers and then "echoing" the
$data to the browser. Could this be why its not working in IE? I;m
really scratching my nut on this one, especially as it works fine in
Firefox.

Cheers

Simon

Simon,

Might I (again) suggest you ask in alt.html? This doesn't look like a
problem with PHP - if it were, it should act the same in both
browsers. Rather, it looks like something IE is doing differently.

And alt.html would have more experts on why IE works different than FF
with the same valid HTML.
Jerry, this has nothing to do with HTML :P.

Headers are part of the HTTP protocol, a markup language doesn't come into
play. You do have a point that in alt.html there are more people aware of
MSIE problems, so allthough it's offtopic there, they might give an answer.
alt.www.webmaster and the like seem more apropriate.

Grtz,
--
Rik Wasmus
Jul 17 '06 #13

P: n/a
Rik wrote:
Jerry Stuckle wrote:
>>Simon Rigby wrote:
>>>I appreciate the help guys but I;m still not having a lot of luck.
The main difference I find in my example from others on the web is
that the examples I have seen apply to a file that already exsists,
whereas in my case I am setting the headers and then "echoing" the
$data to the browser. Could this be why its not working in IE? I;m
really scratching my nut on this one, especially as it works fine in
Firefox.

Cheers

Simon

Simon,

Might I (again) suggest you ask in alt.html? This doesn't look like a
problem with PHP - if it were, it should act the same in both
browsers. Rather, it looks like something IE is doing differently.

And alt.html would have more experts on why IE works different than FF
with the same valid HTML.


Jerry, this has nothing to do with HTML :P.

Headers are part of the HTTP protocol, a markup language doesn't come into
play. You do have a point that in alt.html there are more people aware of
MSIE problems, so allthough it's offtopic there, they might give an answer.
alt.www.webmaster and the like seem more apropriate.

Grtz,
Grtz,

Nope, alt.www.webmaster isn't an appropriate group, either. That's more
about webmastering - not the technical issues (although we do discuss
technical issues at times).

I recommended alt.html because that's the closest you get to http
protocol, and they discuss headers more than any other group I've been in.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 18 '06 #14

P: n/a
Yes you may (again) suggest that I post in alt.html.

Thanks

Jerry Stuckle wrote:
Simon Rigby wrote:
I appreciate the help guys but I;m still not having a lot of luck. The
main difference I find in my example from others on the web is that the
examples I have seen apply to a file that already exsists, whereas in
my case I am setting the headers and then "echoing" the $data to the
browser. Could this be why its not working in IE? I;m really scratching
my nut on this one, especially as it works fine in Firefox.

Cheers

Simon

Simon,

Might I (again) suggest you ask in alt.html? This doesn't look like a
problem with PHP - if it were, it should act the same in both browsers.
Rather, it looks like something IE is doing differently.

And alt.html would have more experts on why IE works different than FF
with the same valid HTML.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 18 '06 #15

This discussion thread is closed

Replies have been disabled for this discussion.