111
public function down(){
$id=I('get.id');
$downLogic = D('Down','Logic');
$where['id'] = $id;
$down = $downLogic -> where($where) ->find();
header("Content-type:text/html;charset=utf-8");
$url = $down['relativepath'];//文件相对位置
$filename = $down['downname'];//文件名字
//$filename=iconv("utf-8","gb2312",$filename); //用以解决中文不能显示出来的问题
//首先要判断给定的文件存在与否
if(!file_exists($url)){
echo "没有该文件";
return;
}
$file = fopen($url,"r"); //打开文件
$filesize = filesize($url);
//下载文件需要用到的头
Header("Content-type: application/octet-stream" ); //通过这句代码客户端浏览器就能知道服务端返回的文件形式
Header("Accept-Ranges: bytes" ); //告诉客户端浏览器返回的文件大小是按照字节进行计算的
Header("Accept-Length: " . $filesize ); //告诉浏览器返回的文件大小
Header("Content-Disposition: attachment; filename=".$filename ); //告诉浏览器返回的文件的名称
$buffer = 1024;
$file_count = 0;
//向浏览器返回数据
while(!feof($file) && $file_count
$file_con = fread($file,$buffer);
$file_count += $buffer;
echo $file_con;
}
fclose($file);
}