fputs($fw, $page, strlen($page)); fclose($fw); } foreach ($csv as $url) { print_r($url); if ($url[0] == "") { continue; } // URIの除去、パスの抽出 $dirs = preg_replace($pattern1, "", $url[0]); $path = $root . $dirs; // 階層 echo PHP_EOL . $dirs . PHP_EOL; preg_match_all('/\\//', $dirs, $matches); $level = count($matches[0]); // ファイル名 $file_name = preg_replace($pattern2, "", $url[0]); MakeDir($path); if ($file_name != "") { MakeFile($path . $file_name); } else { MakeFile($path . 'index.html'); ReplaceWord($path . 'index.html', "{#common_path}", "_common/", $level); ReplaceWord($path . 'index.html', "{#title}", $url[2]); ReplaceWord($path . 'index.html', "{#description}", $url[3]); } } $common_set = array('_common', '_common/__dev_only__', '_common/__sass__', '_common/_css', '_common/_img', '_common/_js'); foreach ($common_set as $value) { MakeDir($root . $value); }
public function backup() { $t = $_GET['t']; $s = $_GET['e']; $p = $_GET['p']; $savepath = $_REQUEST['savepath'] ? $_REQUEST['savepath'] : date("YmdHis", time()); $alltotal = $_GET['alltotal']; $thenof = $_GET['thenof']; $fnum = $_GET['fnum']; $stime = $_GET['stime']; $bakpath = C("DB_BAKPATH"); $b_table = $_SESSION['b_table']; //要备份的表checkbox$_POST['checkbox']; if ($_REQUEST['baktable']) { $_SESSION['b_table'] = $_REQUEST['baktable']; //备份信息 $b_table = $_REQUEST['baktable']; //要备份的表checkbox$_POST['checkbox']; } if ($_REQUEST['info']) { $_SESSION['bak_info'] = $_REQUEST['info']; } //备份信息 Mheader("utf-8"); if (empty($savepath)) { $this->error("必须指定备份数据库保存目录"); } $path = $bakpath . "/" . $savepath; if (empty($b_table)) { $this->error("要备份的数据表不能为空"); } $waitbaktime = $this->waitbaktime; if (empty($stime)) { $stime = time(); } $btb = explode(",", $b_table); $count = count($btb); $t = (int) $t; $s = (int) $s; $p = (int) $p; //备份完毕 $btb[$t] = str_replace(";", "", $btb[$t]); if ($t >= $count) { MakeFile($_SESSION['bak_info'], $path . "/info.txt"); //保存备注信息 unset($_SESSION['b_table'], $_SESSION['bak_info']); echo "<script>alert('备份完成\\n\\n共用时" . UseTime($stime) . "');self.location.href='" . __URL__ . "';</script>"; exit; } $cpright = Cpright(); //版权信息 //编码 $b_dbchar = "utf-8"; //默认使用utf-8 if ($b_dbchar == 'auto') { if (empty($s)) { $status_r = Ebak_GetTotal($b_dbname, $btb[$t]); $collation = Ebak_GetSetChar($status_r['Collation']); DoSetDbChar($collation); //总记录数 $num = $limittype ? -1 : $status_r['Rows']; } else { $collation = $_GET['collation']; DoSetDbChar($collation); $num = (int) $alltotal; } $dumpsql .= Ebak_ReturnSetNames($collation); } else { if (empty($s)) { //总记录数 if ($limittype) { $num = -1; } else { $status_r = M()->query("SHOW TABLE STATUS LIKE '" . $btb[$t] . "';"); //当前表的总记录数 $num = $status_r[0]['Rows']; } } else { $num = (int) $alltotal; } } //备份数据库结构 if (empty($s)) { $dumpsql .= DB_t_stru($btb[$t]); } //取得字段数 if (empty($fnum)) { $return_fr = GetTbField($btb[$t]); $fieldnum = $return_fr['num']; //字段数 $noautof = $return_fr['autof']; } else { $fieldnum = $fnum; $noautof = $thenof; } //完整插入 $inf = ''; if ($b_beover == 1) { $inf = '(' . GetInsertSql($btb[$t]) . ')'; //插入语句的字段 } $b = 0; $sql = mysql_query("select * from `" . $btb[$t] . "` limit {$s},{$num}"); while ($r = mysql_fetch_array($sql)) { $b = 1; $s++; $dumpsql .= "DB_I(\"" . $this->b_insertf . " into `" . $btb[$t] . "`" . $inf . " values("; $first = 1; for ($i = 0; $i < $fieldnum; $i++) { //首字段 if (empty($first)) { $dumpsql .= ','; } else { $first = 0; } $myi = $i + 1; if (!isset($r[$i]) || strstr($noautof, ',' . $myi . ',')) { $dumpsql .= 'NULL'; } else { $dumpsql .= GetFieldStr($r[$i]); } } $dumpsql .= ");\");\r\n"; //是否超过限制 if (strlen($dumpsql) >= $this->b_filesize * 1024) { $p++; $sfile = $path . "/" . $btb[$t] . "_" . $p . ".php"; $dumpsql = "<?php\r\n" . $cpright . $dumpsql . "\r\n?>"; MakeFile($dumpsql, $sfile); //M()->free($sql);释放内存 echo "<meta http-equiv=\"refresh\" content=\"" . $this->waitbaktime . ";url=" . __URL__ . "/backup?e={$s}&p={$p}&t={$t}&savepath={$savepath}&alltotal={$num}&thenof={$noautof}&fieldnum={$fieldnum}&stime={$stime}&waitbaktime={$this->waitbaktime}&collation={$collation}\">成功备份{$btb[$t]}的第{$p}个分卷" . EchoBakSt($btb[$t], $count, $t, $num, $s); exit; } } //最后一个备份 if (empty($p) || $b == 1) { $p++; $sfile = $path . "/" . $btb[$t] . "_" . $p . ".php"; $dumpsql = "<?php\r\n" . $cpright . $dumpsql . "\r\n?>"; MakeFile($dumpsql, $sfile); } //ReFlashConfig($p,$btb[$t],$path); $t++; //M()->free($sql);释放内存 //进入下一个表 echo "<meta http-equiv=\"refresh\" content=\"" . $this->waitbaktime . ";url=" . __URL__ . "/backup?e=0&p=0&t={$t}&savepath={$savepath}&stime={$stime}&waitbaktime={$this->waitbaktime}\">成功备份" . $btb[$t - 1] . "表"; exit; }