批量打印桌贴

发表于

 /**
     * @Author    muyuan
     * @DateTime  2018-01-13
     * @copyright [批量打印桌贴]
     * @license   [license]
     * @version   [version]
     * @param     string      $head [description]
     * @return    [type]            [description]
     */
    public function downzip($head = ‘b’){
        set_time_limit(0);
        ini_set(‘max_execution_time’, ‘0’);
        ini_set(‘memory_limit’, ‘2048M’);
        $datalist = [];
        $num = input(‘num’);//num = 1000,1005
        $arr = explode(‘,’, $num);
        $start = isset($arr[0]) ? (int)$arr[0] : 0;
        $end = isset($arr[1]) ? (int)$arr[1] : 0;
        if(!is_numeric($start) || !is_numeric($end) || $start > $end){
            echo ‘数据格式错误,格式为1000,1002’;die;
        }
        
        $filename = ROOT_PATH . ‘/public/static/bookgo/wxapp/seatnum/done/’.$start.’-‘.$end.’.zip’;
        if(!file_exists($filename)){
            $py = new Python();
            for ($i=$start; $i <= $end ; $i++) {
                $path = $py->py(‘wxapp.img::make_img’,$head,$i);
                $fileurl = ROOT_PATH . ‘/public/static/bookgo/wxapp/seatnum/done/’.$i.’.png’;
                $datalist[] = $fileurl;
            }
            $zip = new \ZipArchive();
            if ($zip->open($filename, \ZipArchive::CREATE)==TRUE) {
                foreach( $datalist as $val){
                    if(file_exists($val)){
                        $zip->addFile( $val, basename($val));
                    }
                }
                $zip->close();
            }
        }
        if(!file_exists($filename)){
            exit(“无法找到文件”);
        }
        header(“Cache-Control: public”);
        header(“Content-Description: File Transfer”);
        header(‘Content-disposition: attachment; filename=’.basename($filename)); //文件名
        header(“Content-Type: application/zip”); //zip格式的
        header(“Content-Transfer-Encoding: binary”); //告诉浏览器,这是二进制文件
        header(‘Content-Length: ‘. filesize($filename)); //告诉浏览器,文件大小
        @readfile($filename);
    }

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注