Home >Backend Development >PHP Tutorial >phpexcel导出中文文件名报错

phpexcel导出中文文件名报错

WBOY
WBOYOriginal
2016-06-13 12:26:281660browse

phpexcel导出中文文件名出错
header("Content-Disposition: attachment;filename=$filename");
$filename是中文的话下载到的文件就是.php的   英文的话可以
------解决思路----------------------
试试

<br />    $user_agent = $_SERVER['Http_User_agent'];  <br />    $encode_filename = rawurlencode($filename); <br /><br />    if(preg_match("/MSIE/", $user_agent)){  <br />        header('content-disposition:attachment; filename="'.$encode_filename.'"');  <br />    }else if(preg_match("/Firefox/", $user_agent)){  <br />        header("content-disposition:attachment; filename*=\"utf8''".$filename.'"');  <br />    }else{  <br />        header('content-disposition:attachment; filename="'.$filename.'"');  <br />    }  <br />

------解决思路----------------------
1、header("Content-Disposition: attachment;filename=$filename"); 必须是不含路径的纯文件名
2、phpexcel 默认字符集是 utf-8,一般人都采用浪费资源的 utf-8 保存程序文件。这就不可避免的可能有 BOM 头

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn