求助:php下载文件乱码问题
我做了一个PHP实现下载网页
但不明白为什么下载后OFFICE文件打开全是乱码,一直不知道怎么解决,以下是我的代码:请高手帮解决;
在此先谢谢了
$file_dir="upload_file/";
$file_name = $file_name;
if (file_exists($file_dir . $file_name))
{
$file = fopen($file_dir . $file_name, "r"); //打开文件
// 输入文件标签
header("Content-type: application/octet-stream;charset=ANSI");
header("Content-type: application/vnd.ms-powerpoint;charset=ANSI");
header("Content-type: application/vnd.ms-excel;charset=ANSI");
header("Content-type: application/msword;charset=ANSI");
header("Content-Type: text/html;charset=utf-8");
header("Accept-Ranges: bytes");
header("Accept-Length: ".filesize($file_dir . $file_name));
header("Content-Disposition: attachment; filename=" . $file_name);
// 输出文件内容
echo fread($file,filesize($file_dir . $file_name));
fclose($file);
}
else
{
die("文件找不到");
}
但不明白为什么下载后OFFICE文件打开全是乱码,一直不知道怎么解决,以下是我的代码:请高手帮解决;
在此先谢谢了
$file_dir="upload_file/";
$file_name = $file_name;
if (file_exists($file_dir . $file_name))
{
$file = fopen($file_dir . $file_name, "r"); //打开文件
// 输入文件标签
header("Content-type: application/octet-stream;charset=ANSI");
header("Content-type: application/vnd.ms-powerpoint;charset=ANSI");
header("Content-type: application/vnd.ms-excel;charset=ANSI");
header("Content-type: application/msword;charset=ANSI");
header("Content-Type: text/html;charset=utf-8");
header("Accept-Ranges: bytes");
header("Accept-Length: ".filesize($file_dir . $file_name));
header("Content-Disposition: attachment; filename=" . $file_name);
// 输出文件内容
echo fread($file,filesize($file_dir . $file_name));
fclose($file);
}
else
{
die("文件找不到");
}
作者: vlonly 发布时间: 2009-05-18
要有人帮忙才行啊!
作者: vlonly 发布时间: 2009-05-18
·双线主机 100M/35元/年,免费送数据库(自选MY/MSSQL)
·详情请访问:http://www.515dns.com
·详情请访问:http://www.515dns.com
作者: opulsq 发布时间: 2009-05-18
不要来这里做你广告啊
我是需要帮助解决问题的
我是需要帮助解决问题的
作者: vlonly 发布时间: 2009-05-18
我也出现这个问题,期待高手帮忙解决
作者: guoluren524 发布时间: 2011-05-20
sword;charset=ANSI");
header("Content-Type: text/html;charset=utf-8");
不知道和这个有没有关系,上面是gbk,下面是utf-8,为什么不统一下呢?
header("Content-Type: text/html;charset=utf-8");
不知道和这个有没有关系,上面是gbk,下面是utf-8,为什么不统一下呢?
作者: kyzy_yy_pm 发布时间: 2011-05-20