200, 'msg'=>'数据库备份成功' ) ); } //备份整个项目目录 public function actionZipdumpdir(){ if(!file_exists('oldversion')){ mkdir('oldversion'); chmod('oldversion',0777,true); } $from =Yii::$app->basePath; //dd($from);die; $to = 'oldversion/zip'.date('Y-m-d H:i:s',time()).'.zip'; if(!file_exists($to)){ touch($to); chmod($to,0777,true); } $zip_result = Zipdump::createZip($from, $to); if($zip_result['success']=1&&$zip_result['message']==''){ echo json_encode( ['code'=>200, 'msg'=>'备份完成' ] ); }else{ echo json_encode( ['code'=>500, 'msg'=>$zip_result['message'] ] ); } } //下载压缩包文件 public function actionUnziptodir(){ $request = Yii::$app->request; if ($request->isGet){ $destination=Yii::$app->request->get()['downname']; //下载前判断文件是否打包 if(!file_exists($destination)){ echo json_encode(['code'=>500,'msg'=>'压缩包不存在']);die; } //下载zip header("Cache-Control: public"); header("Content-Description: File Transfer"); header('Content-disposition: attachment; filename='.basename($destination)); //文件名 header("Content-Type: application/zip"); //zip格式的 header("Content-Transfer-Encoding: binary"); //告诉浏览器,这是二进制文件 header('Content-Length: '. filesize($destination)); //告诉浏览器,文件大小 readfile($destination); exit(); }else{ return false; } } }