/** * 移动文件 * * @access public * @param string $mfile 文件 * @param string $mpath 路径 * @return string */ function MoveFile($mfile, $mpath) { if ($mpath != "" && !preg_match("#\\.\\.#", $mpath)) { $oldfile = $this->baseDir . $mfile; //带路径的mfile $truepath = $this->baseDir . $mpath; //最后带/的truepath if (is_readable($oldfile) && is_readable($truepath) && is_writable($truepath)) { if (is_dir($truepath)) { $r = copy($oldfile, $truepath . basename($mfile)); } else { MakeDir($truepath); copy($oldfile, $truepath . basename($mfile)); } if ($r) { unlink($oldfile); return 1; } else { return 0; } } else { return "移动文件{$oldfile} -> " . $truepath . basename($mfile) . " 失败,可能是某个位置权限不足!"; } } else { return "对不起,你移动的路径不合法!"; } }
function MakeDir($path) { if (!file_exists($path)) { MakeDir(dirname($path)); @mkdir($path, 0777); } }
function get_system_rss_data($para = NULL) { $para = unserialize($para); $data['title'] = isset($para['title']) && strip_tags($para['title']) != '' ? strip_tags($para['title']) : 'Rss'; $data['limit'] = isset($para['limit']) && $para['limit'] != '' ? intval($para['limit']) : '10'; $data['show'] = isset($para['show']) && $para['show'] != '' ? intval($para['show']) : '1'; $data['blog'] = isset($para['blog']) && strip_tags($para['blog']) != '' ? strip_tags($para['blog']) : ''; $data['feed'] = isset($para['feed']) && strip_tags($para['feed']) != '' ? strip_tags($para['feed']) : ''; if (!empty($data['feed'])) { $CI =& get_instance(); $CI->load->library('simplepie'); MakeDir(ROOT . 'static/data/cache'); $CI->simplepie->set_cache_location(ROOT . 'static/data/cache'); $CI->simplepie->set_feed_url($data['feed']); $CI->simplepie->init(); $data['get_items'] = $CI->simplepie->get_items(); $i = 0; foreach ($data['get_items'] as $line) { $i++; if ($i <= $data['limit']) { $data['con'][$i]['feed_title'] = $line->get_title(); $data['con'][$i]['feed_con'] = $line->get_content(); $data['con'][$i]['feed_url'] = $line->get_permalink(); } else { break; } } } return $data; }
public static function uninstall() { global $db, $setting, $admin_cat; $info = self::info(); $db->delete($setting['db']['pre'] . "topic"); $db->exec("drop", "table", $setting['db']['pre'] . "topic"); $db->delete($setting['db']['pre'] . "topic_link"); $db->exec("drop", "table", $setting['db']['pre'] . "topic_link"); $db->delete($setting['db']['pre'] . "admin_cat", array("file", "=", "topic.php")); $db->delete($setting['db']['pre'] . "plugin", array("idx", "=", $info['idx'])); deleteCache("admin_cat"); deleteCache("plugin"); $err = array(); if ($db->GetError($err)) { showInfo($setting['language']['plugin_err_uninstall'] . "\r\n\t\t\t<br />\r\n\t\t\t<pre>\r\n\t\t\t" . join("\n------------------------\n", $err) . "\r\n\t\t\t</pre>\r\n\t\t\t"); } else { includeCache("admin_cat"); $admin_cat = toJson($admin_cat, $setting['gen']['charset']); echo <<<mystep <script language="javascript"> parent.admin_cat = {$admin_cat}; parent.setNav(); </script> mystep; MultiDel(dirname(__FILE__) . "/topic/"); MakeDir(dirname(__FILE__) . "/topic/"); buildParaList("plugin"); echo showInfo($setting['language']['plugin_uninstall_done'], false); } }
function zip($file, $zipfile = "", $basedir = "") { $zip = new MyZip(); $res = false; MakeDir(dirname($zipfile)); if (is_dir($file)) { if (empty($zipfile)) { $zipfile = basename(rtrim($file, '/')) . ".zip"; } $res = $zip->open($zipfile, ZIPARCHIVE::CREATE); if ($res === TRUE) { $zip->addDir($file); $zip->close(); } } elseif (is_file($file)) { if (empty($zipfile)) { $zipfile = str_replace(pathinfo($file, PATHINFO_EXTENSION), "zip", basename($file)); } $res = $zip->open($zipfile, ZIPARCHIVE::CREATE); if ($res === TRUE) { $zip->addFile($file); $zip->close(); } } elseif (is_array($file)) { if (empty($zipfile)) { $zipfile = tempnam(dirname($_SERVER['PHP_SELF']), "") . ".zip"; } $res = $zip->open($zipfile, ZIPARCHIVE::CREATE); if ($res === TRUE) { foreach ($file as $theFile) { if (is_dir($theFile)) { $zip->addDir($theFile); } elseif (is_file($theFile)) { $zip->addFile($theFile); } } $zip->close(); } } if (empty($basedir)) { $basedir = dirname($zipfile) . "/"; } if ($res) { $zip->open($zipfile); for ($i = 0; $i < $zip->numFiles; $i++) { $theName = $zip->getNameIndex($i); $newName = str_replace($basedir, "", $theName); $newName = preg_replace("/\\/+/", "/", $newName); $zip->renameName($theName, $newName); } $zip->close(); } return $res ? $zipfile : false; }
function WriteFile($file_name, $content, $mode = "wb") { //Coded By Windy2000 20040410 v1.0 MakeDir(dirname($file_name)); if ($fp = fopen($file_name, $mode)) { if (flock($fp, LOCK_EX)) { fwrite($fp, $content); flock($fp, LOCK_UN); } else { fwrite($fp, $content); } fclose($fp); @chmod($file_name, 0777); } return $fp; }
public function dozip() { $zippath = C("WEB_ROOT") . C("ZIP_PATH"); $dbpath = C("DB_BAKPATH"); MakeDir($zippath); $bakup = $_REQUEST['bakup']; //zip文件名 $zipname = date("YmdHis", time()) . rand(1, 100) . $bakup . ".zip"; import('ORG.Util.Phpzip'); $z = new PHPZip(); //新建立一个zip的类 $res = $z->Zip($dbpath . "/" . $bakup, $zippath . "/" . $zipname); //添加指定目录 if ($res == 1) { $this->success($zipname, '', __APP__ . "/" . C("ZIP_PATH") . "/" . $zipname); } else { $this->error("压缩失败"); } }
$_POST[$key] = array_sum($value); } else { $_POST[$key] = implode(",", $value); } } if ($setting['gen']['language'] == "en") { if (strpos($key, "_en") > 0) { $_POST[$key] = ucwords(strtolower($value)); } else { $_POST[$key] = itemTrans($value, $key, 1, 0); } } } if (count($_FILES) > 0) { $path_upload = dirname(__FILE__) . "/setting/" . $mid . "/"; MakeDir($path_upload); foreach ($_FILES as $key => $value) { if ($key == "append") { $m = count($_FILES['append']['name']); foreach ($_FILES['append']['name'][0] as $k => $v) { for ($i = 0; $i < $m; $i++) { if (!empty($_FILES['append']['name'][$i][$k])) { $new_name = md5($_FILES['append']['name'][$i][$k] . $_FILES['append']['type'][$i][$k] . $_FILES['append']['size'][$i][$k]); @unlink($path_upload . $new_name); move_uploaded_file($_FILES['append']['tmp_name'][$i][$k], $path_upload . $new_name); $append[$i][$k] = $_FILES['append']['name'][$i][$k] . "::" . $_FILES['append']['type'][$i][$k] . "::" . $new_name; } } } } else { if (!empty($value['name'])) {
} $feed_id = intval(array_shift($args)); if ($feed_id != '0') { $feed = lazy_get_var("SELECT `feed` FROM `app_feed_recommend` WHERE `id` = '" . $feed_id . "' LIMIT 1"); } else { $feed = v('fblog'); if (!$feed || $feed == 'http://') { info_page('你提交的博客地址错误'); } if (strpos($feed, 'http://') === false) { $feed = 'http://' . $feed; } } $CI =& get_instance(); $CI->load->library('simplepie'); MakeDir(ROOT . 'static/data/cache'); $CI->simplepie->set_cache_location(ROOT . 'static/data/cache'); $CI->simplepie->set_feed_url($feed); $CI->simplepie->init(); $data['ftitle'] = $CI->simplepie->get_title(); //标题 $flink = $CI->simplepie->get_link(); //连接地址 if (!$flink) { $flink = $feed; } $data['flink'] = $flink; //delete feed lazy_run_sql("DELETE FROM `app_feed_recommend` WHERE `feed` = '" . $feed . "'"); //type list foreach (app_config('titles') as $k => $v) {
public static function sess_open($sess_path, $sess_name) { MakeDir($sess_path); return true; }
$db->Query(str_replace($strFind, $strReplace, $update_info['sql'][$i])); } if ($m > 0) { $result['info'] = sprintf($setting['language']['admin_update_sql'], $m); } else { $result['info'] = ""; } $plugin_path = ROOT_PATH . "/plugin/" . $idx; $list = array(); for ($i = 0, $m = count($update_info['file']); $i < $m; $i++) { MakeDir(dirname($plugin_path . "/" . $update_info['file'][$i])); if (isWriteable($plugin_path . "/" . $update_info['file'][$i])) { if (empty($update_info['content'][$i])) { @unlink($plugin_path . "/" . $update_info['file'][$i]); } elseif ($update_info['content'][$i] == ".") { MakeDir($plugin_path . "/" . $update_info['file'][$i]); } else { WriteFile($plugin_path . "/" . $update_info['file'][$i], $update_info['content'][$i], "wb"); } } else { $list[] = $i; } } $result['link'] = ""; $m = count($list); if ($m > 0) { require ROOT_PATH . "/source/class/myzip.class.php"; $dir = ROOT_PATH . "/" . $setting['path']['upload'] . "/tmp/"; $zipfile = $dir . "update_" . $idx . "_" . date("Ymd") . ".zip"; $dir = $dir . "update/" . date("Ymd/"); $files = array();
function antilink($folder = NULL, $url = NULL, $base = NULL) { if (!$folder || !$url) { return; } if (!is_dir(ROOT . 'application/app/' . $folder)) { return; } $url = base64_decode($url); $base = base64_decode($base); if (strtolower(substr($url, 0, 7)) != 'http://') { $url = $base . $url; } if (strtolower(substr($url, 0, 7)) != 'http://') { return; } $md5 = md5($url); $web_dir = "static/data/hash/snaps/" . $folder . '/' . myhashstr($md5); $web_file = $web_dir . $md5 . '.gif'; if (file_exists(ROOT . $web_file)) { readfile($web_file); } $parse = parse_url($url); $ref = dirname($url); $this->load->library('snoopy'); $this->snoopy->referer = $ref; if ($this->snoopy->fetch($url)) { MakeDir(ROOT . $web_dir); $remote_file = $this->snoopy->results; file_put_contents(ROOT . $web_file, $remote_file); echo $remote_file; } }
function getplugs() { $this->check_admin(); $id = intval(v('id')); $aid = z(v('aid')); if ($id < 1) { info_page('错误的Id'); } $folder = z(v('folder')); if ($folder == '') { info_page('请填写安装目录'); } $update = false; $path = 'application/app/' . $folder . '/'; if (file_exists(ROOT . $path . 'controller/config.php')) { include ROOT . $path . 'controller/config.php'; if ($app_config['id'] != $aid) { info_page('此目录已安装其他应用'); } else { $update = true; } } $this->load->library('service'); $this->service->add('id', $id); $this->service->add('aid', $aid); $result = $this->service->result('getPlug'); if ($result == false) { info_page('网络错误'); } elseif (!isset($result['flag']) || $result['flag'] != 'ok') { info_page('数据传输错误'); } else { if ($result['error']) { info_page($result['notice']); } else { @MakeDir($path); $file = $path . 'install.zip'; file_put_contents(ROOT . $file, $result['zip']); $this->load->library('pclzip', $file); if ($this->pclzip->extract(PCLZIP_OPT_REPLACE_NEWER, PCLZIP_OPT_PATH, $path) == 0) { info_page("Error : " . $this->pclzip->errorInfo(true)); } @unlink($file); $all_files = app_files('application/app/' . $folder); if ($all_files) { foreach ($all_files as $file) { @touch(ROOT . $file); } } if ($update) { info_page('应用内容已更新', '/admin/applist', '管理应用'); } else { info_page('应用已下载', '/admin/applist', '管理应用'); } } } }
function get_remote_img($content) { $rt = C("WEB_ROOT"); $img_dir = C("REMOTE_IMGDIR") ? C("REMOTE_IMGDIR") : "/UF/Remote"; //img_dir远程图片的保存目录,带前"/"不带后"/" $base_dir = substr($rt, 0, strlen($rt) - 1); //$base_dir网站根目录物理路径,不带后"/" $content = stripslashes($content); $img_array = array(); preg_match_all("/(src|SRC)=[\"|'| ]{0,}(http:\\/\\/(.*)\\.(gif|jpg|jpeg|bmp|png|ico))/isU", $content, $img_array); //获取内容中的远程图片 $img_array = array_unique($img_array[2]); //把重复的图片去掉 set_time_limit(0); $imgUrl = $img_dir . "/" . strftime("%Y%m%d", time()); //img_dir远程图片的保存目录,带前"/"不带后"/" $imgPath = $base_dir . $imgUrl; //$base_dir网站根目录物理路径,不带后"/" $milliSecond = strftime("%H%M%S", time()); if (!is_dir($imgPath)) { MakeDir($imgPath, 0777); } //如果路径不存在则创建 foreach ($img_array as $key => $value) { $value = trim($value); $get_file = @file_get_contents($value); $rndFileName = $imgPath . "/" . $milliSecond . $key . "." . substr($value, -3, 3); $fileurl = $imgUrl . "/" . $milliSecond . $key . "." . substr($value, -3, 3); if ($get_file) { $fp = @fopen($rndFileName, "w"); @fwrite($fp, $get_file); @fclose($fp); } $content = ereg_replace($value, $fileurl, $content); } //$content = addslashes($content); return $content; }
function localPicture($img_list, &$content, $zoom = 700) { global $db, $setting, $req, $pic_list; for ($i = 0, $m = count($img_list); $i < $m; $i++) { if (array_search($img_list[$i], $pic_list) === false) { array_push($pic_list, $img_list[$i]); } else { continue; } if (strpos($img_list[$i], $setting['web']['url']) !== false) { continue; } if (strpos($img_list[$i], getSetting('web', 'url')) !== false) { continue; } $the_time = GetMicrotime(); $old_name = strtolower(basename($img_list[$i])); $ext = "." . GetFileExt($img_list[$i]); $ext = preg_replace("/\\?.*\$/", "", $ext); $old_name = preg_replace("/\\?.*\$/", "", $old_name); $old_name = preg_replace("/[;,&\\=]/", "", $old_name); //if(strpos("*.jpg.bmp.gif.png",$ext)===false) continue; if ($ext == ".") { $ext = ".jpg"; $old_name .= $ext; } if (strlen($old_name) > 120) { $old_name = substr($old_name, -120); } $new_name = $the_time . $ext; $the_path = ROOT_PATH . "/" . $setting['path']['upload'] . date("/Y/m/d/"); MakeDir($the_path); if (GetRemoteFile($img_list[$i], $the_path . $new_name)) { $img_info = GetImageSize($the_path . $new_name); $the_width = $img_info[0]; $the_height = $img_info[1]; if (!is_numeric($zoom)) { $zoom = 700; } if ($the_width > $zoom) { $the_height *= $zoom / $the_width; $the_width = $zoom; } $data = array(0, 0, 0, $old_name, "image" . str_replace(".", "/", $ext), filesize($the_path . $new_name), '', $the_time, 0, '', $req->getSession('username'), $setting['watermark']['mode'] & 2 ? 1 : 0); $db->insert($setting['db']['pre'] . "attachment", $data); $new_id = $db->GetInsertId(); if ($new_id != 0) { $attach_list .= $new_id . ","; $content = str_replace($img_list[$i], $setting['web']['url'] . "/files?" . $new_id, $content); array_push($id_list, $new_id); } $name_new = $the_time . substr(md5(filesize($the_path . $new_name)), 0, 5) . $ext; rename($the_path . $new_name, $the_path . $name_new); MakeDir("{$the_path}/preview/"); img_thumb($the_path . $name_new, $the_width, $the_height, $the_path . "/preview/" . $name_new); } } return $attach_list; }
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); }
function upgrade($id = NULL) { check_admin(); $infos = v('infos'); if (!$infos) { info_page('错误,无数据'); } $this->load->library('service'); $this->service->add('infos', $infos); $res = $this->service->result('getModule'); if ($res == false) { $data['error'] = true; $data['notice'] = '网络错误'; } else { if ($res['flag'] != 'ok') { $data['error'] = true; $data['notice'] = '数据传输错误'; } else { if ($res['error']) { $data['error'] = true; $data['notice'] = $res['notice']; } else { if ($id != $res['fid']) { info_page('错误的组件ID'); } $data['error'] = false; $path = 'application/app/' . $res['folder'] . '/'; MakeDir(ROOT . $path); if (!is_writable(ROOT . $path)) { info_page('错误 目录' . $path . '不可以写'); } file_put_contents($path . 'install.zip', $res['zip']); $data['notice'] = '数据已成功下载到目录' . $path; $data['id'] = $id; } } } $this->view('upgrade', $data); }
break; case "u_update": $header['Referer'] = "http://" . $req->GetServer("HTTP_HOST"); $header['ms_sign'] = $setting['web']['sign']; $update_info = GetRemoteContent($setting['gen']['update'] . "?m=u_update&v=" . $ms_version['ver'] . "&cs=" . $setting['gen']['charset'], $header); if (!empty($update_info)) { $update_info = preg_replace("/(^|[\r\n]+)([\\w]{0,6})[\r\n]+/", "", $update_info); $update_info = base64_decode($update_info); $update_info = unserialize($update_info); $list = array(); for ($i = 0, $m = count($update_info['file']); $i < $m; $i++) { if (isWriteable(ROOT_PATH . "/" . $update_info['file'][$i])) { if (empty($update_info['content'][$i])) { MultiDel(ROOT_PATH . "/" . $update_info['file'][$i]); } elseif ($update_info['content'][$i] == ".") { MakeDir(ROOT_PATH . "/" . $update_info['file'][$i]); } else { WriteFile(ROOT_PATH . "/" . $update_info['file'][$i], $update_info['content'][$i], "wb"); } } else { if (!empty($update_info['content'][$i])) { $list[] = $i; } } } $link = ""; $m = count($list); if ($m > 0) { require ROOT_PATH . "/source/class/myzip.class.php"; $dir = ROOT_PATH . "/" . $setting['path']['upload'] . "/tmp/"; $zipfile = $dir . "update_" . date("Ymd") . ".zip";
function make_pro_icon_dir($uid = NULL) { $uid = format_uid($uid); MakeDir(ROOT . 'static/data/hash/pro_icon/' . myhash($uid)); }
/** +---------------------------------------------------------- * 上传所有文件 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @param string $savePath 上传文件保存路径 +---------------------------------------------------------- * @return string +---------------------------------------------------------- * @throws ThinkExecption +---------------------------------------------------------- */ public function upload($savePath = '') { //如果不指定保存文件名,则由系统默认 if (empty($savePath)) { $savePath = $this->savePath; } // 检查上传目录 if (!is_dir($savePath) && !is_dir(C('WEB_ROOT') . $savePath)) { // 检查目录是否编码后的 if (is_dir(base64_decode($savePath))) { $savePath = base64_decode($savePath); } else { // 尝试创建目录 if (!MakeDir(C('WEB_ROOT') . $savePath)) { $this->error = '上传目录' . $savePath . '不存在'; return false; } } } else { if (!is_writeable($savePath) && !is_dir(C('WEB_ROOT') . $savePath)) { $this->error = '上传目录' . $savePath . '不可写'; return false; } } $fileInfo = array(); $isUpload = false; // 获取上传的文件信息 // 对$_FILES数组信息处理 $files = $this->dealFiles($_FILES); foreach ($files as $key => $file) { //过滤无效的上传 if (!empty($file['name'])) { //登记上传文件的扩展信息 $file['key'] = $key; $file['extension'] = $this->getExt($file['name']); $file['savepath'] = $savePath; $file['savename'] = $this->getSaveName($file); // 自动检查附件 if ($this->autoCheck) { if (!$this->check($file)) { return false; } } //保存上传文件 if (!$this->save($file)) { return false; } if (function_exists($this->hashType)) { $fun = $this->hashType; $file['hash'] = $fun($this->autoCharset($file['savepath'] . $file['savename'], 'utf-8', 'gbk')); } //上传成功后保存文件信息,供其他地方调用 unset($file['tmp_name'], $file['error']); $fileInfo[] = $file; $isUpload = true; } } if ($isUpload) { $this->uploadFileInfo = $fileInfo; return true; } else { $this->error = '没有选择上传文件'; return false; } }