public function load() { $matches = glob(EPHP_BACKUP . "/" . $this->user . "/*"); if (count($matches) == 1) { $filename = substr($matches[0], strrpos($matches[0], "/") + 1); return array("src" => file_get_contents($matches[0]), "filename" => $filename == "unnamed" ? "" : $filename); } return array("src" => "", "filename" => ""); } public function clear() { } } if (!isset($_SESSION["ephpuser"])) { header("HTTP/1.1 401 Unauthorized"); } else { $bkp = new Backup($_SESSION["ephpuser"]); switch ($_SERVER["REQUEST_METHOD"]) { case "GET": header("Content-type: application/json"); echo json_encode($bkp->load()); break; case "POST": if (isset($_POST["src"]) && ($_POST["filename"] == "" || preg_match("/^[\\w\\.]+\$/", $_POST["filename"]))) { $bkp->save($_POST["src"], $_POST["filename"]); } elseif (isset($_POST["delete"])) { $bkp->clear(); } break; } }
/** * 配置数据备份 */ public function backup() { Backup::clear(); $this->assign("table", M()->getTableInfo()); $this->display(); }