public function download(){
$id = input('id');
$item = Db::name('imgsubmit')->where(['id'=>$id])->find();
Db::name('imgsubmit')->where(['id'=>$id])->update(['status'=>1]);
$tt = ltrim($item['zip'],'uploads/');
$path = config('upload_path').DS.$tt;
$arr = explode('/',$path);
$iname=$item['username'].'_'.$item['order_no'];
$filename=$iname.'.zip';
if (file_exists($path)) {
$filesize=filesize($path);
header('Content-Description:File Transfer');
header("Content-Type:application/octet-stream");
header('Content-Transfer-Encoding:binary');
header("Accept-Ranges: bytes");
header('Expires:0');
header('Cache-Control:must-revalidate');
header('Pragma:public');
header("Content-Length:".$filesize);
header("Content-Disposition:attachment;filename=".$filename);
$fp = fopen($path, "rb");
ob_start();
fseek($fp,0);
while (!feof($fp)) {
set_time_limit(0);
print (fread($fp, 1024 * 8));
flush();
ob_flush();
}
fclose($fp);
exit ();}else{echo "文件不存在!!!";die();}
}
本文转自lb沫51CTO博客,原文链接:http://blog.51cto.com/13562606/2066555,如需转载请自行联系原作者