1

我有一个脚本可以将 mysql 结果输出到 excel,它在所有浏览器中都可以正常工作。但是,我需要脚本也可以在 iPad 上工作,在 Safari 中打开 excel。此时,脚本只是“挂起”在 iPad 上,它一直在加载。这是标题问题吗?此时的代码头:

header( 'Content-Transfer-Encoding: binary' );
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Content-Type: application/vnd.ms-excel');
//header("Content-Type: application/octet-stream");
header('Content-Disposition: attachment;filename="' . $_POST['Client_FirstName'] . ' ' .     $_POST['Client_LastName'] . ' ' . $_POST['month'] . '-' . $_POST['year'] . '.xlsx"');
header('Cache-Control: max-age=0');
header("Pragma: public");
header("Expires: 0");
4

1 回答 1

2

显然是导致问题的 application/vnd.ms-excel 标头。将其设置为 octet-stream 解决了该问题,但随后导致 IE8 出现问题。所以我用这段代码完全解决了这个问题:

if(stristr($_SERVER['HTTP_USER_AGENT'], 'ipad') OR stristr($_SERVER['HTTP_USER_AGENT'],     'iphone') OR stristr($_SERVER['HTTP_USER_AGENT'], 'ipod')) 
{ 
  header("Content-Type: application/octet-stream"); 
}else{ 
  header('Content-Type: application/vnd.ms-excel'); 
}
于 2012-07-13T10:01:13.240 回答