大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
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 = $arr[count($arr)-1];*/
$filename=$iname.'.zip';
//$file = fopen($path, "rb");
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();}
}