Thinkphp批量下载文件下的图片-打包下载

//批量下载图片
    public function download_img_all(){
        $dfile = tempnam('./public/upload/qr_code/', 'tmp');//产生一个临时文件,用于缓存下载文件
        $zip = new Zipfile();
        $filename = 'erweima'.'.zip'; //下载的默认文件名
        // $image  = M('Device')->field('erweima')->select();
        // foreach($image as $v){
        //     $image_path = './public/upload/qr_code/';方法一
        //      $zip->add_path($image_path);
        //      // $zip->add_file(file_get_contents($v['erweima']), $v['erweima']);
        //      // 添加打包的图片,第一个参数是图片内容,第二个参数是压缩包里面的显示的名称, 可包含路径
        //      // 或是想打包整个目录 用 
        // }
        $image_path = './public/upload/qr_code/';//方法二
        $zip->add_path($image_path);
        $zip->output($dfile);
        // 下载文件
        ob_clean();
        header('Pragma: public');
        header('Last-Modified:'.gmdate('D, d M Y H:i:s') . 'GMT');
        header('Cache-Control:no-store, no-cache, must-revalidate');
        header('Cache-Control:pre-check=0, post-check=0, max-age=0');
        header('Content-Transfer-Encoding:binary');
        header('Content-Encoding:none');
        header('Content-type:multipart/form-data');
        header('Content-Disposition:attachment; filename="'.$filename.'"'); //设置下载的默认文件名
        header('Content-length:'. filesize($dfile));
        $fp = fopen($dfile, 'r');
        while(connection_status() == 0 && $buf = @fread($fp, 8192)){
         echo $buf;
        }
        fclose($fp);
        @unlink($dfile);
        @flush();
        @ob_flush();
        exit();
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值