【发布时间】:2011-10-25 07:58:40
【问题描述】:
我正在尝试使用 php 和 mysql 将数据从数据库导出到 Excel 工作表。 它在 IE 和所有浏览器中的本地主机中运行良好,但在 IE 中的真实网站(hostmonster 站点)中失败。它说文件无法下载。
这是我生成动态数据并提供下载的示例代码:
<?php
while($node_stmt = mysql_fetch_array($result))
{
$contents.="\t\t".$node_stmt['uniqueid']."\t";
$contents.=$node_stmt['title'].' '.
ucfirst($node_stmt['firstname']).' '.
ucfirst($node_stmt['lastname'])."\t";
$contents.=$node_stmt1['topic']."\t";
$contents.=$abst."\t";
$contents.=$node_stmt['email']."\t";
$contents.=$node_stmt['phoneno']."\t";
$contents.=$pay."\t";
$contents.=$node_stmt['state_id']."\t";
$contents.=$node_stmt['country_id']."\n";
}
.....
header('Content-Transfer-Encoding: none');
header('Content-Type: application/vnd.ms-excel;'); // This should work for IE & Opera
header("Content-type: application/x-msexcel"); // This should work for the rest
header('Content-Disposition: attachment; filename="'.basename($filename).'"');
echo $contents;
?>
我需要更改主机或 IE 的任何设置吗?
【问题讨论】:
-
你有没有试过不发送application/x-msexcel给ie,而只发送application/vnd.ms-excel?只需对 $_SERVER["HTTP_USER_AGENT"] 做一个简单的 if 检查即可。
标签: php internet-explorer export-to-excel