function xCopy($source, $destination, $child) { //用法: // xCopy("feiy","feiy2",1):拷贝feiy下的文件到 feiy2,包括子目录 // xCopy("feiy","feiy2",0):拷贝feiy下的文件到 feiy2,不包括子目录 //参数说明: // $source:源目录名 // $destination:目的目录名 // $child:复制时,是不是包含的子目录 if (!is_dir($source)) { echo "Error:the {$source} is not a direction!"; return 0; } if (!is_dir($destination)) { mkdir($destination, 0777); } $handle = dir($source); while ($entry = $handle->read()) { if ($entry != "." && $entry != "..") { if (is_dir($source . "/" . $entry)) { if ($child) { xCopy($source . "/" . $entry, $destination . "/" . $entry, $child); } } else { copy($source . "/" . $entry, $destination . "/" . $entry); } } } return 1; }
/** * 复制文件夹(递归)到目标文件夹 **/ function xCopy($source, $destination) { if (substr($source, -1) == "/") { $source = substr($source, 0, -1); } if (substr($destination, -1) == "/") { $destination = substr($destination, 0, -1); } if (!is_dir($source)) { return 0; } if (!is_dir($destination)) { mkdir($destination, 0777); } $destination = $destination . "/" . basename($source); if (!is_dir($destination)) { mkdir($destination, 0777); } $handle = dir($source); while ($entry = $handle->read()) { if ($entry != "." && $entry != "..") { if (is_dir($source . "/" . $entry)) { xCopy($source . "/" . $entry, $destination); } else { copy($source . "/" . $entry, $destination . "/" . $entry); } } } return 1; }
function xCopy($source, $destination, $child) { if (!is_dir($source)) { echo "Error:the {$source} is not a direction!"; return 0; } mkdirs($destination); $handle = dir($source); while ($entry = $handle->read()) { if ($entry != "." && $entry != "..") { if (is_dir($source . "/" . $entry)) { if ($child) { xCopy($source . "/" . $entry, $destination . "/" . $entry, $child); } } else { copy($source . "/" . $entry, $destination . "/" . $entry); } } } return 1; }
public function copyDir($source, $destination, $child) { if (!is_dir($destination)) { mkdir($destination, 0777); } $handle = dir($source); while ($entry = $handle->read()) { if ($entry != '.' && $entry != '..') { if (is_dir($source . '/' . $entry)) { if ($child) { xCopy($source . '/' . $entry, $destination . '/' . $entry, $child); } } else { if (file_exists($destination . '/' . $entry)) { unlink($destination . '/' . $entry); } if (!copy($source . '/' . $entry, $destination . '/' . $entry)) { return false; } } } } return true; }
/** * 复制 widget所需文件 到用户目录 */ function download_widget_link($public_rootpath) { $widgetpath = "." . C('WIDGET_PUBLIC_PATH'); xCopy($widgetpath, $public_rootpath); }
/** * 拷贝文件 * $source:源目录名 * $destination:目的目录名 * $child:复制时,是不是包含的子目录 * xCopy("feiy", "feiy2", 1): 拷贝feiy下的文件到 feiy2, 包括子目录 * xCopy("feiy", "feiy2", 0): 拷贝feiy下的文件到 feiy2, 不包括子目录 */ function xCopy($source, $destination, $child) { if (!is_dir($source)) { return 0; } if (!is_dir($destination)) { mkdir($destination, 0777); } $handle = dir($source); while ($entry = $handle->read()) { if ($entry != "." && $entry != "..") { if (is_dir($source . "/" . $entry)) { if ($child) { xCopy($source . "/" . $entry, $destination . "/" . $entry, $child); } else { copy($source . "/" . $entry, $destination . "/" . $entry); } } } } return 1; }
public function install() { $return_rs = array('msg' => '安装成功', 'status' => true); //用于返回的数据 $db_config['DB_HOST'] = $_REQUEST['DB_HOST']; $db_config['DB_NAME'] = $_REQUEST['DB_NAME']; $db_config['DB_USER'] = $_REQUEST['DB_USER']; $db_config['DB_PWD'] = $_REQUEST['DB_PWD']; $db_config['DB_PORT'] = $_REQUEST['DB_PORT']; $db_config['DB_PREFIX'] = $_REQUEST['DB_PREFIX']; $demo_data = intval($_REQUEST['DEMO_DATA']); $connect = @mysql_connect($db_config['DB_HOST'] . ":" . $db_config['DB_PORT'], $db_config['DB_USER'], $db_config['DB_PWD']); if (mysql_error() == "") { $rs = mysql_select_db($db_config['DB_NAME'], $connect); if ($rs) { $return_rs['status'] = true; } else { $db_rs = mysql_query("create database " . $db_config['DB_NAME'] . " DEFAULT CHARACTER SET utf8"); if ($db_rs) { $return_rs['status'] = true; } else { $return_rs['msg'] = "创建数据库失败"; $return_rs['status'] = false; } } } else { $return_rs['msg'] = "连接数据库失败"; $return_rs['status'] = false; } if ($return_rs['status']) { //开始将$db_config写入配置 $db_config_str = "<?php\r\n"; $db_config_str .= "return array(\r\n"; foreach ($db_config as $key => $v) { $db_config_str .= "'" . $key . "'=>'" . $v . "',\r\n"; } $db_config_str .= ");\r\n"; $db_config_str .= "?>"; @file_put_contents($this->getRealPath() . "/public/db_config.php", $db_config_str); //开始执行安装脚本 if ($demo_data == 1) { xCopy($this->getRealPath() . "/install/demofile", $this->getRealPath() . "/public", 1); $msg = $this->restore($this->getRealPath() . "/install/install_demo.sql", $db_config); } else { $msg = $this->restore($this->getRealPath() . "/install/install_blank.sql", $db_config); } if ($msg == "") { @file_put_contents($this->install_lock, ""); $this->success($return_rs['msg'], 1); } else { $this->error($msg, 1); } } else { $this->error($return_rs['msg'], 1); } }
$intro = str_replace("<br />", "</p><p>", $intro); $sql = "update qiyu_site set site_logo='" . $logo . "',site_icon='" . $icon . "',site_icp='" . $icp . "',site_isshowcomment='" . $comment_status . "',site_isshowprotocol='" . $protocol_status . "',site_isshowadminindex='" . $admin . "',site_protocol='" . $intro . "',site_isshowcard='" . $card . "'"; if (mysql_query($sql)) { //echo 'ok'; alertInfo('操作成功', '', 1); } else { //echo 'fail'; alertInfo('出错', '', 1); } break; case "tmp": $tmp = sqlReplace(trim($_POST['tmp'])); //更新相应的模板 $from_dir = "template/" . $tmp; $to_dir = "../"; if (!xCopy($from_dir, $to_dir, 1)) { alertInfo('更新文件失败', '', 1); } else { $sql = "update qiyu_site set site_tmp=" . $tmp . ""; if (mysql_query($sql)) { alertInfo('操作成功', '', 1); } else { alertInfo('出错', '', 1); } } break; case "other": $onlinechat = sqlReplace(trim($_POST['onlinechat'])); $iscartfoodtag = sqlReplace(trim($_POST['iscartfoodtag'])); $cartfoodtag = sqlReplace(trim($_POST['cartfoodtag'])); $stat = sqlReplace(trim($_POST['stat']));
function xCopy($source, $destination, $child) { if (!file_exists($destination)) { if (!mkdir(rtrim($destination, '/'), 0777)) { //$err->add($_LANG['cannt_mk_dir']); return false; } @chmod($destination, 0777); } if (!is_dir($source)) { return 0; } if (!is_dir($destination)) { mkdir($destination, 0777); } $handle = dir($source); while ($entry = $handle->read()) { if ($entry != "." && $entry != "..") { if (is_dir($source . "/" . $entry)) { if ($child) { xCopy($source . "/" . $entry, $destination . "/" . $entry, $child); } } else { copy($source . "/" . $entry, $destination . "/" . $entry); } } } return 1; }
xCopy($dirb, $dira, 1); $dira = $met_htmpack_url . 'public/banner/'; $dirb = "../../public/banner/"; xCopy($dirb, $dira, 1); $dira = $met_htmpack_url . 'public/images/'; $dirb = "../../public/images/"; xCopy($dirb, $dira, 1); $dira = $met_htmpack_url . 'public/js/'; $dirb = "../../public/js/"; xCopy($dirb, $dira, 1); $dira = $met_htmpack_url . 'public/css/'; $dirb = "../../public/css/"; xCopy($dirb, $dira, 1); $dira = $met_htmpack_url . 'public/ui/'; $dirb = "../../public/ui/"; xCopy($dirb, $dira, 1); $dira = $met_htmpack_url . 'favicon.ico'; $dirb = "../../favicon.ico"; copy($dirb, $dira); } $methtm[] = indexhtm(1, $htmpack); //module 1 foreach ($met_classindex[1] as $key => $val) { $methtm[] = showhtm($val[id], 1, $htmpack); if ($val['releclass']) { foreach ($met_class3[$val[id]] as $key => $val3) { if ($val3[isshow]) { $methtm[] = showhtm($val3[id], 1, $htmpack); } } } else {
public function install() { @set_time_limit(3600); if (function_exists('ini_set')) { ini_set('max_execution_time', 3600); } $from_items = C("FROM_ITEMS"); $submit = true; $error_msg = array(); foreach ($from_items as $key => $items) { if (isset($_REQUEST[$key]) && is_array($_REQUEST[$key])) { foreach ($items as $k => $v) { $from_items[$key][$k]['value'] = $_REQUEST[$key][$k]; if (empty($_REQUEST[$key][$k]) || !preg_match($v['reg'], $_REQUEST[$key][$k])) { if (empty($_REQUEST[$key][$k]) && !$v['required']) { continue; } else { $submit = false; $from_items[$key][$k]['error'] = 1; } } } } } if ($from_items['admin']['ADM_PWD']['error'] == 1) { $from_items['admin']['ADM_PWD2']['error'] = 0; } else { $from_items['admin']['ADM_PWD']['notice'] = ''; if ($_REQUEST['admin']['ADM_PWD'] != $_REQUEST['admin']['ADM_PWD2']) { $submit = false; $from_items['admin']['ADM_PWD2']['error'] = 1; } } $_SESSION['from_items'] = $from_items; if (!$submit) { $this->assign("froms", $from_items); $this->assign("DEMO_DATA", $demo_data); $this->display("database"); exit; } $db_config = $_REQUEST['dbinfo']; $user_config = $_REQUEST['admin']; $this->display(); $status = true; $connect = @mysql_connect($db_config['DB_HOST'] . ":" . $db_config['DB_PORT'], $db_config['DB_USER'], $db_config['DB_PWD']); if (mysql_error() == "") { $rs = mysql_select_db($db_config['DB_NAME'], $connect); if (!$rs) { $db_rs = mysql_query("CREATE DATABASE IF NOT EXISTS `" . $db_config['DB_NAME'] . "` DEFAULT CHARACTER SET utf8"); if (!$db_rs) { $status = false; showjsmessage('', -1); showjsmessage("创建数据库失败", 1); } } } else { $status = false; showjsmessage('', -1); showjsmessage("连接数据库失败", 1); } if (!$status) { exit; } $db = Db::getInstance(array('dbms' => 'mysql', 'hostname' => $db_config['DB_HOST'], 'username' => $db_config['DB_USER'], 'password' => $db_config['DB_PWD'], 'hostport' => $db_config['DB_PORT'], 'database' => $db_config['DB_NAME'])); $tables = $db->query("SHOW TABLES LIKE '" . $db_config['DB_PREFIX'] . "%'"); foreach ($tables as $table) { $db->query("DROP TABLE IF EXISTS " . current($table)); } flush(); ob_flush(); showjsmessage('', -1); showjsmessage("开始安装程序", 2); //开始将$db_config写入配置 $db_config_str = "<?php\r\n"; $db_config_str .= "return array(\r\n"; foreach ($db_config as $key => $v) { $db_config_str .= "'" . $key . "'=>'" . $v . "',\r\n"; } $db_config_str .= ");\r\n"; $db_config_str .= "?>"; @file_put_contents(FANWE_ROOT . "public/db.global.php", $db_config_str); //开始执行安装脚本 if ($demo_data == 1) { $status = $this->restore(FANWE_ROOT . "install/install_demo.sql", $db_config); if ($status) { xCopy(FANWE_ROOT . "install/demofile", FANWE_ROOT . "public/upload", 1); } } else { $status = $this->restore(FANWE_ROOT . "install/install.sql", $db_config); } if ($status) { if ($user_config['ADM_NAME'] != "fanwe" || $user_config['ADM_PWD'] != "fanwe") { $sql = "UPDATE " . $db_config['DB_PREFIX'] . "admin SET admin_name = '" . $user_config['ADM_NAME'] . "',admin_pwd = '" . md5($user_config['ADM_PWD']) . "' WHERE id = 1"; $db->query($sql); if ($admins['ADM_NAME'] != "fanwe") { $sql = "UPDATE " . $db_config['DB_PREFIX'] . "sys_conf SET val = '" . $user_config['ADM_NAME'] . "' WHERE name = 'SYS_ADMIN'"; $db->query($sql); } } $authkey = substr(md5($_SERVER['SERVER_ADDR'] . $_SERVER['HTTP_USER_AGENT'] . $db_config['DB_HOST'] . $db_config['DB_USER'] . $db_config['DB_PWD'] . $db_config['DB_NAME'] . $user_config['ADM_NAME'] . $user_config['ADM_PWD'] . '0' . substr(time(), 0, 6)), 8, 6) . random1(10); $cookiepre = random1(4) . '_'; $memory_prefix = random1(6) . '_'; $configfile = @file_get_contents(FANWE_ROOT . 'public/config.global.php'); $configfile = trim($configfile); $configfile = preg_replace("/[\$]config\\['memory'\\]\\['prefix'\\].*?=.*?'.*?'.*?;/is", "\$config['memory']['prefix'] = '" . $memory_prefix . "';", $configfile); $configfile = preg_replace("/[\$]config\\['cookie'\\]\\['cookie_pre'\\].*?=.*?'.*?'.*?;/is", "\$config['cookie']['cookie_pre'] = '" . $cookiepre . "';", $configfile); $configfile = preg_replace("/[\$]config\\['security'\\]\\['authkey'\\].*?=.*?'.*?'.*?;/is", "\$config['security']['authkey'] = '" . $authkey . "';", $configfile); @file_put_contents(FANWE_ROOT . 'public/config.global.php', $configfile); @file_put_contents($this->install_lock, ""); Vendor('common'); include_once fimport('class/cache'); Cache::getInstance()->updateCache(); showjsmessage("安装成功", 4); } }
$file_path = $cgi[file_path]; if($file_path == "") $file_path = "$file_base/$db_name/pc"; pub_mkdir("$file_path/upload"); if($is_window) { @unlink("$file_path/temp_view.php"); copy("$root_path/temp_view.php", "$file_path/temp_view.php"); @unlink("$file_path/addmess.php"); copy("$root_path/addmess.php", "$file_path/addmess.php"); xCopy("$root_path/plib", "$file_path/plib"); xCopy("$root_path/pagelib", "$file_path/pagelib"); } else { $cmd = "cd $file_path; rm -f temp_view.php; ln -s $root_path/temp_view.php temp_view.php"; system($cmd); $cmd = "cd $file_path; rm -f addmess.php; ln -s $root_path/addmess.php addmess.php"; system($cmd); $cmd = "cd $file_path; ln -s $root_path/plib plib"; system($cmd); $cmd = "cd $file_path; ln -s $root_path/pagelib pagelib";
function xCopy($source, $destination, $child) { if (!is_dir($source)) { return false; } if (!file_exists($destination)) { mkdir($destination, 0777, true); } $handle = dir($source); while ($entry = $handle->read()) { if ($entry != '.' and $entry != '..') { if (is_dir($source . '/' . $entry)) { if ($child) { xCopy($source . '/' . $entry, $destination . '/' . $entry, $child); } } else { copy($source . '/' . $entry, $destination . '/' . $entry); } } } return true; }