PHP 下载导出中文名的文件的编码注意事项
2015-12-21 22:38
886 查看
我的页面全部都为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..才能找到文件
相关文章推荐
- ubuntu下tftp安装、配置、
- php学习日记第八棒(一个 IP 和多个域名绑定)
- PHP 支持8种基本的数据类型
- 1. thinkphp (1)
- matplotlib简明教程
- php之smarty分配变量
- php 类的构造方法 __construct
- PHP学习练手(三)
- PHP中获取文件扩展名的N种方法
- Zend Studio/Eclipse更改背景风格主题
- Windows Server 2008 阿里云服务器(ECS)配置FTP传输
- ThinkPHP3.2版本—视图与模板
- php 过滤特殊字符 如 ◆ )- : 、 、!! / 等
- ThinkPHP3.2实现简单的数据分页
- 安装vsftpd
- smarty中调用php内置函数
- ftp工具-filezilla搭建(windows环境下)
- 802.1D,STP感悟
- php分享十四:php接口编写
- 微软Visual Studio "14" CTP 2 公布