我的页面全部都为utf-8
在代码中我的文件名是中文名.
在创建文件时,就要将utf-8转码成gbk(用以支持中文)
$file = iconv(‘utf-8‘,"gbk",$file); $fileHandle = fopen($file, ‘w+‘);
然后...
我代码经过了一系列处理.
经过了页面ajax传递.此时应该又变成了utf-8编码
我在最后下载时..再次转码 $file = iconv(‘utf-8‘,"gbk",$file) if(!file_exists($file)){ //检查文件是否 echo "文件找不到"; exit;
}else{
header(‘Content-Description: File Transfer‘);
header(‘Content-Type: application/octet-stream‘);
header(‘Content-Disposition: attachment; filename=‘.$fileEnName);
header(‘Content-Transfer-Encoding: binary‘);
header(‘Expires: 0‘);
header(‘Cache-Control: must-revalidate, post-check=0, pre-check=0‘);
header(‘Pragma: public‘);
header(‘Content-Length:‘.filesize($file));
readfile($file);
}
在判断文件时.. file_exists($file)
如果文件名是中文名..则一定要进行转码.将utf-8转码成gbk..才能找到文件
原文:http://www.cnblogs.com/meibao/p/5065115.html