I have made a script that outputs a XLS file with data brought from my database. Problem is that when you view the file on OSX and Linux it looks as it is supposed to.
Behaviour on Windows
On Windows excel shows the following message.
The file format and extension 'nameofthefile.xls' don't match. The file could be corrupted or unsafe. Unless you trust.....
Have you ever faced this problem?
$sql = "MY SQL QUERY";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
$output .= '<table class="table" border="1"
<tr>
<th>MY Table heads</th>
<th>MY Table heads</th>
</tr>';
$count = 1;
while ($row = mysqli_fetch_array($result)) {
$data = strtotime($row['reg_date']);
$format_date = date("d.M.Y", $data);
$output .= '
<tr>
<td>' . $count++ . '</td>
<td>' . $row["id"] . '</td>
<td>' . $row["firstname"] . '</td>
<td>' . $row["lastname"] . '</td>
<td>' . $format_date . '</td>
</tr>';
}
$output .= '</table>';
header("Content-Type: application/xls");
header("Content-Disposition: attachement; filename=download.xls");
echo $output;
}
}