您的位置:首页 > 编程语言 > PHP开发

解决PHP文件(word/excel)下载 内容打开乱码问题

2015-11-18 17:32 1016 查看
编码转换不一定有用,一般可以解决文件名乱码问题

iconv(
'utf-8'
,
'gb2312'
,
$filename
);


具体代码如下:

header(
"Pragma: public"
);

  
header(
"Cache-control: max-age="
.
$expire
);

  
//header('Cache-Control: no-store, no-cache, must-revalidate');

  
header(
"Expires: "
.
gmdate
(
"D, d M Y H:i:s"
,time()+
$expire
) .
"GMT"
);

  
header(
"Last-Modified: "
.
gmdate
(
"D, d M Y H:i:s"
,time()) .
"GMT"
);

  
header(
"Content-Disposition: attachment; filename="
.
$showname
);

  
header(
"Content-Length: "
.
$length
);

  
header(
"Content-type: "
.
$type
);

  
header(
'Content-Encoding: none'
);

  
header(
"Content-Transfer-Encoding: binary"
);

//**********************************

  
ob_clean();

 
flush
();

//*********************************

  
readfile(
$filename
);


注意上面的两行代码

ob_clean();

flush
();

参考:http://gaoke0820.blog.163.com/blog/static/216649652013152945362/?suggestedreading&wumii
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: