tp5 rc 3 数据库备份扩展

浏览:1622 最后更新:2016-11-12 23:25 分类:类库
扩展目录
\extend\org

使用方法 控制器//数据库备份
    public function bak(){
       $type=input("tp");
       $name=input("name");
       $sql=new \org\Baksql(\think\Config::get("database"));
       switch ($type)
        {
        case "backup": //备份
          return $sql->backup();
          break;  
        case "dowonload": //下载
          $sql->downloadFile($name);
          break;  
        case "restore": //还原
          return $sql->restore($name);
          break; 
        case "del": //删除
          return $sql->delfilename($name);
          break;          
        default: //获取备份文件列表
            return $this->fetch("db_bak",["list"=>$sql->get_filelist()]); 
          
        }
        
    }
前台<button type="button" class="btn btn-info" onclick="handle('backup')">添加备份</button>
                <div class="table-responsive">
                    <table class="table table-striped">
                      <thead>
                        <tr>
                          <th>序号</th>
                          <th>备份名称</th>
                          <th>备份时间</th>
                          <th>备份大小</th>
                          <th>操作</th>
                        </tr>
                      </thead>
                      <tbody>
                      {volist name="list" id="vo"}
                        <tr>
                          <th scope="row">{$key}</th>
                          <td>{$vo.name}</td>
                          <td>{$vo.time}</td>
                          <td>{$vo.size}</td>
                          <td>
                          <a class="btn btn-xs btn-success" href="{:url('bak',['tp'=>'dowonload','name'=>$vo.name])}">下载</a>
                          <button type="button" class="btn btn-xs btn-warning" onclick="handle('restore','{$vo.name}')">还原</button>
                          <button type="button"  class="btn btn-xs btn-danger" onclick="handle('del','{$vo.name}')">删除</button>
                          </td>
                        </tr>    
                        
                      {/volist}
                      
                        
                      </tbody>
                    </table>
            </div>
js <script>
    function handle(tp,name=''){        
        if (tp){
            $.post("{:url('bak')}",{tp:tp,name:name},function(response){
                if (response){
                    jSuccess(response, {VerticalPosition: 'center',HorizontalPosition: 'center'}); 
                }else{
                    jError("操作失败,请重试!!", {VerticalPosition: 'center',HorizontalPosition: 'center'});
                }
    
            }); 
        }
    }
</script>
最终效果
评论( 相关
后面还有条评论,点击查看>>