我们在首页控制器Index重定向到了Bak控制器中,即数据库管理所有操作方法。备份的数据库放在根目录文件夹databak中,接着引入MySQLReback类。
$DataDir = "databak/"; mkdir($DataDir); import("Common.Org.MySQLReback"); $mr = new MySQLReback($config); $mr->setDBName(C('DB_NAME'));
备份:
if ($_GET['Action'] == 'backup') { $mr->backup(); echo " "; $this->success( '数据库备份成功!'); } 还原: $mr->recover($_GET['File']); echo " ";
删除:
if ($_GET['Action'] == 'Del') { if (@unlink($DataDir . $_GET['File'])) { // $this->success('删除成功!'); echo " "; } else { $this->error('删除失败!'); } }
读取备份的所有数据库列表
$lists = $this->MyScandir('databak/');
下载:
if ($_GET['Action'] == 'download') { function DownloadFile($fileName) { ob_end_clean(); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Length: ' . filesize($fileName)); header('Content-Disposition: attachment; filename=' . basename($fileName)); readfile($fileName); } DownloadFile($DataDir . $_GET['file']); exit(); } }
文章来源“购过瘾”网,素质转载尊重原创者