ober Posted August 19, 2010 Share Posted August 19, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/211173-forced-download-not-working-in-ie/ Share on other sites More sharing options...
nblackwood Posted August 19, 2010 Share Posted August 19, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/211173-forced-download-not-working-in-ie/#findComment-1101212 Share on other sites More sharing options...
ober Posted August 19, 2010 Author Share Posted August 19, 2010 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... :'( Quote Link to comment https://forums.phpfreaks.com/topic/211173-forced-download-not-working-in-ie/#findComment-1101215 Share on other sites More sharing options...
nblackwood Posted August 19, 2010 Share Posted August 19, 2010 The only other thing I can think of is to create a temp folder on your server and have your script create the file there. Quote Link to comment https://forums.phpfreaks.com/topic/211173-forced-download-not-working-in-ie/#findComment-1101221 Share on other sites More sharing options...
ober Posted August 19, 2010 Author Share Posted August 19, 2010 Well, that's what it is doing now... using the windows temp folder because I seem to have a permission problem somewhere that is not allowing me to write to anything in the DOCUMENT_ROOT. Quote Link to comment https://forums.phpfreaks.com/topic/211173-forced-download-not-working-in-ie/#findComment-1101222 Share on other sites More sharing options...
PFMaBiSmAd Posted August 19, 2010 Share Posted August 19, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/211173-forced-download-not-working-in-ie/#findComment-1101251 Share on other sites More sharing options...
ober Posted August 19, 2010 Author Share Posted August 19, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/211173-forced-download-not-working-in-ie/#findComment-1101272 Share on other sites More sharing options...
ober Posted August 19, 2010 Author Share Posted August 19, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/211173-forced-download-not-working-in-ie/#findComment-1101333 Share on other sites More sharing options...
ober Posted August 19, 2010 Author Share Posted August 19, 2010 <?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. Quote Link to comment https://forums.phpfreaks.com/topic/211173-forced-download-not-working-in-ie/#findComment-1101336 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.