PHP Exporting to Excel, on iPad

若如初见. 提交于 2019-12-25 01:38:50

问题


I have a script to output a mysql result to excel, which is working just fine in all browsers. However, I need the script to also work on iPad, opening the excel in Safari. At this moment, the script just "hangs" on the iPad, it keeps loading. Is this a headers problem? The code headers at this moment:

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");

回答1:


Apparently it was the application/vnd.ms-excel header that caused the problem. Setting it to octet-stream solved the issue, but then caused problems in IE8. So I used this code to totally solve the problem:

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'); 
}


来源:https://stackoverflow.com/questions/11449989/php-exporting-to-excel-on-ipad

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!