Mar 09 2006

PHP, SSL, File Output and Internet Explorer Error

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.

5 Comments

  • By Jay, 7/13/2006 @ 11:17 AM

    I found your soution to be exactly what I needed to solved the problem I was having. Thanks!

  • By Jose, 7/26/2006 @ 11:18 AM

    Thanks a lot, my production server works just fine now.

  • By tolleiv, 9/26/2006 @ 6:13 AM

    Thanks you for sharing your experience – that saved my day. Thanks.

  • By Ben Wong, 4/27/2007 @ 2:57 PM

    Dude! Thanks.

    You saved me hours of time googling/debugging a script.

  • By Grateful, 12/3/2007 @ 10:27 PM

    Another huge thanks! It would’ve taken me hours upon hours to find this work-around.

Other Links to this Post

RSS feed for comments on this post. TrackBack URI

Leave a comment