安然不哭-西坝阿超个人博客

做技术一定要一颗恒心,这样才不会半途而废。

php打包批量下载

2018-7-22 钟建超

        $zip = new \ZipArchive();
        $filename = 'download.zip';
        $zip->open($filename,\ZIPARCHIVE::OVERWRITE | \ZIPARCHIVE::CREATE);
        $list=db("workpeo")->where("id","in",input("ids"))->select();

        foreach ($list as $key=>$value) {

            $zip->addFile("./public/uploads/".$value["file"],$value["title"].date("Y.m.d h:i:s",$value["times"]).".".$this->get_extension($value["file"]));
        }
        $zip->close();
        header('Location:'.$filename);
        header("Cache-Control: public");
        header("Content-Description: File Transfer");
        header('Content-disposition: attachment; filename='.basename($filename)); //文件名
        header("Content-Type: application/force-download");
        header("Content-Transfer-Encoding: binary");
        header('Content-Length: '. filesize($filename)); //告诉浏览器,文件大小
        readfile($filename);




这个 ZipArchive 是php自带的类库

标签: php