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?
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";
Comment