thinkphp5整合Phpzip进行网站备份压缩

4676

下载phpzip地址:http://www.oschina.net/code/snippet_167936_6898

修改phpzip 在头部加上 

namespace think; 然后放在 \thinkphp\library\think 文件夹中[核心目录]

 //提交压缩文件

    public function webzip () {
       if (request()->isPost()) {
           set_time_limit(0);
           //获取路径
           $dir = input("post.dir"); //需要压缩目录 例如 ./ 或者 /app
           if (!file_exists($this->path)) {
               @mkdir($this->path); //保存的目录 例如 /public/static/weback/
           }
           $filename = $this->path."usezan".date('Ymd').".zip"; //最终生成的文件名(含路径)
           $archive = new PHPZip();
           if(!file_exists($filename)){
               $archive->Zip($dir,$filename);
           } else {
               //存在就删除、再压缩
               @unlink($filename);
               $archive->Zip($dir,$filename);
           }
           $this->success('网站压缩成功',url('webbak/index'));
       } else{
           return $this->fetch();
       }
   }