您的位置:首页 > 编程语言 > PHP开发

解决在IE下使用PHPExcel导出时的文件名中文乱码问题

2018-03-05 18:01 856 查看
在使用PHPExcel导出文件时,IE浏览器或者和IE使用同一内核的浏览器需要使用
urlencode
对中文文件名进行转换才可以正常显示。

...
$ua = $_SERVER['HTTP_USER_AGENT'];
$ua = strtolower($ua);
if(preg_match('/msie/', $ua) || preg_match('/edge/', $ua)) { //判断是否为IE或Edge浏览器
$excel_name = str_replace('+', '%20', urlencode($excel_name)); //使用urlencode对文件名进行重新编码
}

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header("Content-Disposition: attachment;filename= '{$excel_name}.xlsx'");
...
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐