473,395 Members | 1,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Forced download issue with IE6

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
14 1783
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
I'll try that Rik. But I'm interested to know why its bad practice?

Simon

Jul 13 '06 #3
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
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
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
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
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
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

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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: dany | last post by:
I want a forced PDF-download but all that header-stuff is new for me.... I wrote a little asp-script: <% Filename = "download.pdf" response.addheader "content-disposition","attachment;...
1
by: dany | last post by:
Wrote a script (tried to;) which should force to download a pdf-file, but it doesn't work on every browser. What should be changed ? SCRIPT: --------- <% Dim Stream Dim Contents
2
by: Gary D. Rezek | last post by:
Hi All, First of all I'm mostly an MS Access guy (and novice learning MSSQL guy) and put on this project because of personnel changes, etc and because of db experience. I've only been doing this...
5
by: Richard | last post by:
Hi, I'm writing an MS Outlook 2000 Addin in C#. I have created C# classes that monitor folder events and do other business logic. Things work fine until I want to exit Outlook. When I exit...
5
by: fbwhite | last post by:
I know this issue has been brought up many times, but I have tried many of the solutions to no avail. I wanted to give my specific case to see if someone could be of any help. We are using the...
1
by: darren | last post by:
Dear Groups, I have a hosted application which allows subscribers to purchase PDF documents. Once purchased, these documents are accessible from a user private library to be downloaded at will....
13
by: Mickey | last post by:
Hi all, Currently I use a timestamp to log users out after 15 minutes of inactivity. However I also need to log a user out if they have just left the page. I need to do this because I store...
2
by: comp.lang.php | last post by:
if ($forceDownload) { // HANDLE FORCED DOWNLOAD $dlGen =& new DownloadGenerator($fullFilePath); $negativeIndex = $dlGen->generateForceDownloadHeaders(); $willDeleteTemp =...
12
by: comp.lang.php | last post by:
index.php: // STUFF // STEP 1: imagecreatetruecolor ONLY IF GD 2.0+ SUPPORTED AND FOUND if ($this->isSuccessful && !$hasMogrified && $image && !$newImage &&...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.