473,804 Members | 3,720 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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($fi lesize)) {
$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($se archTerm, $searchType);
$data = '';
while($row = mysql_fetch_ass oc($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 1814
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*******@attgl obal.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*******@attgl obal.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*******@attgl obal.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*******@attgl obal.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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4115
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; filename=" & Filename server.transfer Filename %> It only works with Internet Exporer (mac & pc) but not with Opera, Netscape
1
3657
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
2900
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 for about 2 months. I need to know how to "force" a download (patch) from an ASP page. I am developing an on-line internet registration page for students in the Residence Halls. Part of this project is getting their Res Hall/room number/port, MAC...
5
1957
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 Outlook I have to force 2 garbage collection cycles in order for all of my folder monitor classes to get cleaned up {else Outlook will not unload from memory}. In other words my OnDisconnect() method looks something like this:
5
5295
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 sessionstate inproc mode and users are randomly losing their session. I do not believe it is happening across all users at one time. It seems to happen to different users at different times, but I am only going off heresay. The aspnet worker...
1
1632
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. All is well with this process except for one Windows XP computer which keeps returning PDFs with nothing in them resulting in an error similar to "Acrobat cannot open this document, the file type is either unsupported or damaged, etc".
13
2321
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 current online users in a database, allowing a maximum of 5 users at one time. I have been looking through the php manual and came across session_cache_expire(). This isn't doing what I need either. Am I
2
1427
by: comp.lang.php | last post by:
if ($forceDownload) { // HANDLE FORCED DOWNLOAD $dlGen =& new DownloadGenerator($fullFilePath); $negativeIndex = $dlGen->generateForceDownloadHeaders(); $willDeleteTemp = $dlGen->getSession('willDeleteTemp'); if (!$dlGen->isSuccessful) $errorArray = $dlGen->getErrorArray(); if ((int)$negativeIndex !== -1 && $willDeleteTemp) { if ($dlGen->getSession('album')) { $locationPath = "${'tmp' . ucfirst($dlGen->getSession('section'))...
12
2849
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 && function_exists('imagecreatetruecolor') && preg_match('/2\.0/i', $this->gd_info_array)) { $newImage = @imagecreatetruecolor($configArray, $configArray);
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9582
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10335
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10323
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9157
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7621
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6854
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2993
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.