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

在使用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'");
...
posted on 2018-06-27 16:38  jurui  阅读(332)  评论(0编辑  收藏  举报