/** * 打包下载备份包 *@param $file 文件路劲 *@examlpe */ public function downzip($file) { import('ORG.Util.phpzip'); $addzip = new phpzip(); import('ORG.Net.FileSystem'); $path = new FileSystem(); $path->root = ITEM; $path->charset = C('CFG_CHARSET'); load("@.download"); //main $file = strval($file); $realpath = CONF_PATH . 'Backup/' . $file; $bakfile = RUNTIME_PATH . 'Temp/Zip/'; if (!file_exists($bakfile)) { $path->putDir($bakfile); } $zipname = 'Backup_' . $file . '.zip'; $zippath = $bakfile . $zipname; $addzip->zip($realpath, $zippath); if (file_exists($zippath)) { download($zippath); $path->delFile($zippath); } unset($addzip, $path); }
//访问权限检查 if (!$objWebInit->checkPopedomG($_SESSION['user_id'])) { check::AlertExit('对不起,您没有权限访问此页', -1); } if ($_SERVER["REQUEST_METHOD"] == "POST") { @set_time_limit(0); /* 系统信息 */ $sys_info['os'] = PHP_OS; $sys_info['web_server'] = $_SERVER['SERVER_SOFTWARE']; $sys_info['php_ver'] = PHP_VERSION; $sys_info['mysql_ver'] = $objWebInit->get_ver(); $sys_info['date'] = date("Y-m-d H:i:s"); $date = date("Y-m-d"); $head = "-- BIWEB SQL Dump \n" . "-- http://www.biweb.cn \n" . "-- \n" . "-- DATE : " . $sys_info["date"] . "\n" . "-- MYSQL SERVER VERSION : " . $sys_info['mysql_ver'] . "\n" . "-- PHP VERSION : " . $sys_info['php_ver'] . "\n" . "-- Vol : "; $sql = $head . " 1 \n-- \n-- DATABASE : " . $arrGPdoDB['db_name'] . "\n-- \n\n-- ---------------------------------\n"; $zip = new phpzip(); $vol_size = $_POST['vol_size']; $sql_name = $_POST['sql_name']; $i = 1; $error = 0; if (!$objWebInit->creat_cache($sql)) { die("不能建立缓存文件!"); } $arrTables = $objWebInit->get_table(); foreach ($arrTables as $k => $table) { if (!$objWebInit->get_table_df($table, $sql, $_POST['drop_tab'])) { $error = 1; break; } if (!$objWebInit->get_table_content($table, $sql, $_POST['ext_insert'])) { $error = 1;
/** * 数据库还原 */ public function dbrestore() { @set_time_limit(0); $dataDir = "../#data/db/"; $action = !empty($_GET['action']) ? $_GET['action'] : ""; if ("import" == $action && !empty($_GET['file'])) { $filename = $_GET['file']; $oriFilename = ""; if (eregi(".zip\$", $filename)) { $oriFilename = $filename; $filename = eregi_replace(".zip\$", ".sql", $filename); $zip = new phpzip(); $zip->unzip($dataDir . $oriFilename, $dataDir); } if (!($fp = fopen($dataDir . $filename, "r"))) { exit("File not found."); } $sql = ""; while (!feof($fp)) { $line = trim(fgets($fp, 524288)); if (ereg(";\$", $line)) { $sql .= $line; $db->query($sql); $sql = ""; } else { if (!ereg("^(//|--)", $line)) { $sql .= $line; } } } fclose($fp); if (!empty($oriFilename)) { unlink($dataDir . $filename); } $tpl->assign("msg", "数据恢复成功!"); $tpl->assign("backUrl", "db_import.php"); $tpl->display("_msg.tpl"); exit; } if ("delete" == $action && !empty($_GET['file']) || unlink($dataDir . $_GET['file'])) { header("location: ?"); exit; } $arrSqls = array(); if ($handle = @opendir($dataDir)) { while (FALSE !== ($file = readdir($handle))) { if (is_file($dataDir . $file)) { $arrSqls[] = array("file" => $file, "size" => filesize($dataDir . $file)); } } closedir($handle); } $this->assign("arr", $arrSqls); $this->display(); }