I have this script to export mysql data to excel. I have tried everything but I am not able to get this script to work for IE. The script downloads the data using FireFox or Chrome but IE fails and says:
Internet Explorer cannot download list_view.php from www.mysite.com. (this is the site on which the file resides).
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 is the code that I am using:
$sql = "SELECT...."
$result = mysql_query($sql)
or die("\nError Retrieving Records.<hr />sql: $sql<hr />ERROR:".mysql_error());
if(mysql_num_rows($result) > 0){
// build a filename that excel will use to save it as
$filename=$name."_".dateFromDB($_GET['confDate']).".xls";
// headers to force the open/save into Excel
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$filename");
header("Pragma: no-cache");
header("Expires: 0");}?>
<table>
<thead>
<tr>
<th>address</th>
<th>phone</th>
<th>email</th>
<th>status</th>
</tr>
</thead>
<tbody>
<?php // loop over items
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) { ?>
<tr>
<td><?=$row['address'];?></td>
<td><?=$row['phone'];?></td>
<td><?=$row['email'];?></td>
<td><?=$row['status'];?></td>
</tr><?php
}?>
</tbody>
</table><?php
exit(); // exit or it will throw an error when it tries to continue
I know there maybe some people suggesting not to use IE, but the person who is actually using the export function do not have access to different browser.
EDIT:
I forgot to mention that I am running a SSL(https). If i turn SSL off everything is working fine on IE, but the moment SSL is on the IE shows an error.
Any ideas how to make it work under SSL?
Instead of outputting everything as a table, can you just output it as CSV, either manually formatting it, or something like
implode('","', $row)
? Leave the content-type header the way it is. I've had success doing that, even in IE.Headers
Headers can be tricky with IE. Here's the thing, you should set it not to cache like this:
Now there can be an issue with that if your server time is not set to the right timezone, this may actually have the opposite effect and force IE to cache it. Make sure your timezone is set for the correct timezone you are in. Is it a shared server? do you have ssh access??
Excel Headers
Now what you need is to provide the set of headers for IE
Try that, hopefully it should work.