I export php data to Excel using the following script:
This give a pop-up message 'The file format and extension of ... do not match ... Do you want to open it anyway?' If, however, I select 'yes' here the file opens normally, so what is the problem?
Code:
$db = mysqli_connect(HOST, USER, PASS) or die(mysqli_error($db));
mysqli_select_db($db, DBNAME);
$q="SELECT * FROM foo";
$result = mysqli_query($db,$q) or die();
$tsv = array();
while ($row = mysqli_fetch_array($result, MYSQLI_NUM))
{
$tsv[] = implode("\t", $row);
}
$tsv = implode("\r\n", $tsv);
$fileName = 'myfile.xls';
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$fileName");
echo $tsv;
mysqli_free_result($result);
mysqli_close($db);
This give a pop-up message 'The file format and extension of ... do not match ... Do you want to open it anyway?' If, however, I select 'yes' here the file opens normally, so what is the problem?