我想從數據庫導出數據到Excel表,使用PHP和MySQL。 它在IE和所有瀏覽器中的本地主機上正常工作,但在IE(主機監控站點)的真實網站中失敗。它說該文件無法下載。PHP出口到Excel無法在IE瀏覽器的網站
這是生成動態數據,並提供我的示例代碼下載:
<?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瀏覽器的任何設置?
您是否嘗試過不發送應用程序/ x-msexcel的IE瀏覽器,而是隻發送應用程序/ vnd.ms - Excel中?只要做一個簡單的檢查$ _SERVER [「HTTP_USER_AGENT」]。 –