Download Table to Excel in secure https for IE

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • andrewteg
    New Member
    • Aug 2007
    • 22

    Download Table to Excel in secure https for IE

    I have the following code which has been working great in IE, FF, and Safari. However, it is not behind a certificate so it's https and now no longer works in IE. I am simply trying to download a SQL statement to XL.

    I found some info here on the site about removing the no-cahce header but that does not help. If I remove the Content-Disposition header it loads XL in IE but does not find the data to open.

    Can anyone help me find this answer?

    Code:
    $header = "";
    $data = "";
    $strSQL = "SELECT * FROM table";
    $result = mysql_query($strSQL);
    $fields = mysql_num_fields($result);
    for ($i = 0; $i < $fields; $i++) {
    	$header .= mysql_field_name($result, $i) . "\t";
    }
    while($row = mysql_fetch_row($result)) {
    	$line = '';
    	foreach($row as $value) {
    			if ((!isset($value)) OR ($value == "")) {
    				$value = "\t";
    			} else {
    				$value = str_replace('"', '""', $value);
    				$value = str_replace("+", ",", $value);
    				$value = '"' . $value . '"' . "\t";
    				//if (substr($value,1,1) == ",") {
    				//}
    			}
    		$line .= $value;
    	}
    	$data .= trim($line)."\n";
    }
    $data = str_replace("\r","",$data);
    if ($data == "") {
    	$data = "\n(0) Records Found!\n";
    }
    header("Content-type: application/vnd.ms-excel");
    header("Content-Disposition: attachment; filename=MyQuery.xls");
    header("Pragma: no-cache");
    header("Expires: 0");
    echo "$header\n$data";
  • andrewteg
    New Member
    • Aug 2007
    • 22

    #2
    It appears the solution in this case is a combination of removing the header("Pragma: no-cache"); and also adding session_cache_l imiter("must-revalidate"); before any session_start commands.

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hey.

      Glad you found a solution. Thanks for sharing it!

      I've seen some very odd behavior in IE (odder that usual, that is) when doing data transfer via HTTPS. Never really found a solution. (Kind of just accepted it as another IE *bug*).

      I'll have to keep this in mind next time that comes up :)

      Comment

      Working...