我做了一个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("文件找不到");
}
·详情请访问:http://www.515dns.com
header("Content-Type: text/html;charset=utf-8"); 不知道和这个有没有关系,上面是gbk,下面是utf-8,为什么不统一下呢?