Jump to content

Forced download not working in IE


ober

Recommended Posts

I am generating a snapshot of some data and giving the users the ability to download that snapshot.  I am trying to serve that file to the users and it works great in Firefox, but the IE users just get a blank file.  I'm using the following:

 

<?php
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Pragma: no-cache');
header('Content-Type: text/plain; charset=ISO-8859-1'); // plain text file
$filename = 'C:\WINDOWS\Temp\snapshot.txt';
header("Content-Disposition: attachment; filename=\"".$filename."\";" );
header("Content-Length: ".filesize($filename));
readfile("$filename");
?>

 

I've changed multiple items several times and each works in FF, but none work in IE.  Is anyone aware of any IE specific headers that need to be sent?  It's just a plain text file, nothing fancy.

Link to comment
Share on other sites

IE has a bunch of problems with headers. I have had a similar problem before, and my solution was to use a separate download link on the page they view the file results. Try this:

 

<a href="<?php echo $filename;?>">For IE users, click here to download the file</a>

 

 

Link to comment
Share on other sites

I can't do that because the file isn't in the web server's path.  I'm actually grabbing it from outside of the public access.  So I have to be able to do this.  I guess my other option would be to copy it to another location after processing it, but it seems to be insane that this isn't possible.  It works great in FF...  :'(

Link to comment
Share on other sites

Not this problem again.

 

I think the problem has to do with your web server outputting a content-type header for a .php file and/or IE automatically treating .php files the way it wants instead of the way you want.

 

Are you on an Apache web server so that you could use url rewriting to make it look like you are not using a .php file as the URL in the download link?

Link to comment
Share on other sites

Nope, IIS.  And here's the weird thing.  When I browse on the server and go to the properties of the folder, the 'read only' checkbox is 'half-checked', if you know what I mean.  I uncheck it, hit ok, come back in and it's back to 'half-checked'... like I never touched it.

 

But the weird thing is, the temp folder where I was able to write to also has the same setting.

Link to comment
Share on other sites

OK, it gets even more weird.  I can create an xlsx file in another directory and I can create a .dat file in this directory, but now the .dat file gets served as an empty file, even though I can see it and there is definitely data in it.

Link to comment
Share on other sites

<?php
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Pragma: no-cache');
header('Cache-Control: private',false);
header('Content-Type: binary'); // plain text file
$filename = 'test.dat';
header("Content-Disposition: attachment; filename=\"".$filename."\";" );
header("Content-Length: ".filesize($filename));
readfile("$filename");
?>

 

Well, I wrote the results to a .dat file and now it is serving it appropriately.  WEIRD.  Oh well, all is well that ends well.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.