解决在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'");
...

猜你喜欢

转载自blog.csdn.net/hwhsong/article/details/79449036
今日推荐