thinkphp 导出excel不弹出保存窗口直接输出怎么办?
这是代码。ob_start();//打开缓冲区header("Content-Type:application/force-download");header("Cach...
这是代码。
ob_start (); //打开缓冲区
header("Content-Type: application/force-download");
header ( "Cache-Control: public" );
Header ( "Content-type: applicationnd.ms-excel" );
Header ( "Accept-Ranges: bytes" );
$groupName = mb_convert_encoding ( str_replace ( " ", "-", $groups ["groupName"] ) . "-预算单", "GBK", "UTF-8" ); //文件名转码
if (strpos ( $_SERVER ["HTTP_USER_AGENT"], 'MSIE' )) {
header ( 'Content-Disposition: attachment; filename=' . $groupName . '.xls' );
} else if (strpos ( $_SERVER ["HTTP_USER_AGENT"], 'Firefox' )) {
Header ( 'Content-Disposition: attachment; filename=' . $groupName . '.xls' );
} else {
header ( 'Content-Disposition: attachment; filename=' . $groupName . '.xls' );
}
header ( "Pragma:no-cache" );
header ( "Expires:0" );
ob_end_flush (); //输出全部内容到浏览器
应该出现这个图片的
但是现在直接输出了
没有一下代码就可以下载 有的话就不行 展开
ob_start (); //打开缓冲区
header("Content-Type: application/force-download");
header ( "Cache-Control: public" );
Header ( "Content-type: applicationnd.ms-excel" );
Header ( "Accept-Ranges: bytes" );
$groupName = mb_convert_encoding ( str_replace ( " ", "-", $groups ["groupName"] ) . "-预算单", "GBK", "UTF-8" ); //文件名转码
if (strpos ( $_SERVER ["HTTP_USER_AGENT"], 'MSIE' )) {
header ( 'Content-Disposition: attachment; filename=' . $groupName . '.xls' );
} else if (strpos ( $_SERVER ["HTTP_USER_AGENT"], 'Firefox' )) {
Header ( 'Content-Disposition: attachment; filename=' . $groupName . '.xls' );
} else {
header ( 'Content-Disposition: attachment; filename=' . $groupName . '.xls' );
}
header ( "Pragma:no-cache" );
header ( "Expires:0" );
ob_end_flush (); //输出全部内容到浏览器
应该出现这个图片的
但是现在直接输出了
没有一下代码就可以下载 有的话就不行 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询