While working on a project, everything was working on our beta site just fine. Once we moved the project to the production site, we ran into an issue on a page that exported a csv file of information inline. The only difference was that the production site was running SSL.
The basic situation is as follows. A script written on PHP, running on Apache, through a SSL connection is dynamically generating a file (in our case a csv) and then sending it to the client. This works correctly through Firefox, but returns an error in Internet Explorer. The error returned is:
Internet Explorer cannot download <url of link>
Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later.
Here’s a hint, no matter how many times you try again later, it will not work. I started with this code:
header("Content-type: application/csv\n");
header("Content-Disposition: attachment; filename=\"$filename\"; size=$size");
After much research, I found the way to fix this is through the Pragma header, making sure it’s anything BUT off-cache. Once I add a new header, it worked fine through both Firefox and Internet Explorer:
header("Content-type: application/csv\n");
header("Content-Disposition: attachment; filename=\"$filename\"; size=$size");
header("Pragma: turn-off-cache", true);
I just changed it to turn-off-cache, but anything typed in instead of off-cache would work fine.