189 8069 5689

PHP大文件下载(方式1不支持断点续传)

 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();}

}

分享标题:PHP大文件下载(方式1不支持断点续传)
网页路径:http://jkwzsj.com/article/jhepgs.html

其他资讯