文件下载有关问题-有的word文件下载后乱码或显示警告,代码如下。求指点。

WBOY
Release: 2016-06-13 10:17:36
Original
941 people have browsed it

文件下载问题-有的word文件下载后乱码或显示警告,代码如下。求指点。。。
$id=$_GET['download']; //从现在页面获取该文件数据库中的ID
  $conn=mysql_connect('localhost','root','');
/* if(!$conn) 
{
echo('数据库连接失败!');
exit;
}
else echo '连接成功!';*/
  $flag=mysql_select_db('laborder' ,$conn);
$sql="select * from files where files_id=$id";
mysql_query("set names gbk");
  $result = mysql_query($sql,$conn); 
$lists=mysql_fetch_array($result);
  $file_name=$lists["files_name"];// 获取文件名
$file_dir="uploadfiles/";//标出文件所在目录
 
$file = fopen($file_dir . $file_name, "r "); // 打开文件  
// 输入文件标签 
Header( "Content-type: application/octet-stream "); 
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); 
exit;

------解决方案--------------------

PHP code
$contents=fread($file,filesize($file_dir . $file_name));echo iconv("UTF-8", "GBK",$contents);fclose($file);  exit;<br><font color="#e78608">------解决方案--------------------</font><br>
Copy after login
探讨

不乱才有问题!

把文件存为没有BOM的UTF8格式
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!