php下载的文件中文乱码

jianglin28290 2008-06-17 02:08:38
$second=time();
header("Content-type: application/force-download");
//header("Cache-Control: private");
header('Content-Transfer-Encoding: utf-8');
header("Content-Type: text/csv; name=rapport".$second.".rtf");
//header("Content-Type: application/rtf");
header("Content-Disposition: attachment;filename=rapport".$second.".rtf");
header("Pragma: no-cache");
header("Expires: 0");
文件打开后中文变成乱码,哪位有解决方法?
...全文
291 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
adama 2008-06-18
  • 打赏
  • 举报
回复
你尝试一下变换编码。比如 utf-8 -> gb2312 或者 gb2312 -> utf-8
<?php
echo iconv("ISO-8859-1", "UTF-8", "This is a test.");
?>
http://cn.php.net/manual/en/function.iconv.php
Dleno 2008-06-18
  • 打赏
  • 举报
回复
function download($filename){
$timestamp=time();
ob_end_clean();
header('Last-Modified: '.gmdate('D, d M Y H:i:s',$timestamp+86400).' GMT');
header('Cache-control: max-age=86400');
header('Expires: '.gmdate('D, d M Y H:i:s',$timestamp+86400).' GMT');
header('Content-Encoding: none');
$basename = basename($filename);
$fileext = substr(strrchr($basename,'.'),1);
$filesize = filesize($filename);;
if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')!==false && $fileext=='torrent' ){
$attachment='inline';
} else{
$attachment='attachment';
}
header('Content-Disposition: '.$attachment.'; filename='.$basename);
header('Content-type: '.$fileext);
$filesize && header('Content-Length: '.$filesize);
readfile($filename);
exit;
}
majia12ofdollyn 2008-06-17
  • 打赏
  • 举报
回复
想了想,发觉没那么简单.
jianglin28290 2008-06-17
  • 打赏
  • 举报
回复
用rtf写中文是必须用\'吗?
但是我要把utf-8格式的中文写进去啊,用内码能行吗??
jianglin28290 2008-06-17
  • 打赏
  • 举报
回复
我时用rtf命令写进去然后下载,有没有哪个命令可以更改编码的。
我看到word上显示的iso-8859-1的格式
my_web 2008-06-17
  • 打赏
  • 举报
回复
我以前用gb2312好像没有这个问题
jianglin28290 2008-06-17
  • 打赏
  • 举报
回复
数据从文件里读的.utf-8格式
mrshelly 2008-06-17
  • 打赏
  • 举报
回复
数据从哪里来的?

数据的编码是什么格式???

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧