$id=$_GET['download']; //从现在页面获取该文件数据库中的ID
$conn=mysql_connect('localhost','root','');
/* if(!$conn)
{
echo('<b>数据库连接失败!</b>');
exit;
}
else echo '<b>连接成功!</b>';*/
$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;
------解决方案--------------------