不清楚 fastadmin 自定义搜索 带入 export 的 可以看上一篇
/** * 导出zip */ public function export(){ $filter = $this->request->param("filter"); list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $path = str_replace('\\','/',realpath(dirname(__FILE__).'/../../../../'))."/public/file/qrcode/".date('Ymd')."/"; $zip_path = str_replace('\\','/',realpath(dirname(__FILE__).'/../../../../'))."/public/file/qrcode/zip"; if(!file_exists($path)){ mkdir($path,0777,true); } $list = $this->model ->where($where) ->order($sort, $order) ->select(); if(empty($list)){ return json(array('code'=>1,'error'=>"暂无记录")); } $arr = []; foreach ($list as $key => $val) { if($val['qrcode_image'] != ""){ // 遍历每个,生成对应的图片文件并添加到文件夹 $imageData = @file_get_contents(config('site.api_url').$val['qrcode_image']); $imageName = $path . $val['qrcode'] . ".png"; file_put_contents($imageName, $imageData); } } if(!file_exists($zip_path)){ mkdir($zip_path,0777,true); } $zip_name = date('YmdHis').rand(1000,9999); //$url = "/file/qrcode/zip/".$zip_name.".zip"; Makezip::zip($path,$zip_path."/".$zip_name.".zip"); // // 输出到浏览器下载 header('Content-Type: application/zip'); header('Content-Transfer-Encoding: Binary'); header('Content-disposition: attachment; filename='.$zip_name.".zip"); header('Content-Length: ' . filesize($zip_path."/".$zip_name.".zip")); // 这两行很重要,不然可能会出现解压的时候提示文件损坏 ob_clean(); flush(); readfile($zip_path."/".$zip_name.".zip"); // // 删除服务器上的ZIP文件(可选) // unlink($zip_path."/".$zip_name.".zip"); }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步