private function pathed($name) { if (!isset($this->path[$name])) { if ( !is_dir($this->dir) ) { tmkdir($this->dir); } $this->path[$name] = $this->dir . $this->mixd($name) . '.lock'; } return $this->path[$name]; }
/** * @copyright (C)2014 Cenwor Inc. * @author Cenwor <www.cenwor.com> * @package php * @name cache.func.php * @date 2014-09-01 17:24:22 */ function cache($name,$lifetime=null,$only_get=false) { static $_filelist,$_lastfile,$_file,$_caches; $path ="./cache/"; if($lifetime!==null) { if($_file!==null)$_lastfile=$_file; $_file=$path.$name.'.cache.php'; $_filelist[$_file]=$_lastfile; $file=$_file; if($only_get)$_file=null; if ($lifetime===0) return @unlink($file); if($_caches[$name.$lifetime]!==null)return $_caches[$name.$lifetime]; @$cache_exists=include($file); if($cache_exists && ($lifetime===-1 || @filemtime($file)+$lifetime>time()))return $_caches[$name.$lifetime]=$cache; } else { if($_file===null)if($_lastfile===null)return false;else $_lastfile=$_filelist[$_file=$_lastfile]; if(@is_writeable($path)===false)return @trigger_error("缓存目录 $path 不可写",E_USER_WARNING); if(@is_dir($cache_dir=@dirname($_file))==false) { tmkdir($cache_dir); } $data=var_export($name,true); $data="<?php \r\n\$cache=$data;\r\n?>"; @$fp=fopen($_file,"wb"); @flock($fp, LOCK_EX); @$len=fwrite($fp,$data); @flock($fp, LOCK_UN); @fclose($fp); $_file=null; return $len; } return false; }
function setDstImg($dst_img) { $arr = explode('/',$dst_img); $last = array_pop($arr); $path = implode('/',$arr); tmkdir($path); $this->dst_img = $dst_img; }
private function __write_cache($class, $format, $content) { $dir = CACHE_PATH.'/export/'; if (!is_dir($dir)) { @tmkdir($dir); } $file = $class.'_'.date('YmdHis').'.'.$format; file_put_contents($dir.$file, ENC_IS_GBK ? $content : ENC_U2G($content)); return $file; }
public function write($key, $value) { $path = self::$path; $file = $path.$key.'.cache.php'; tmkdir(dirname($file)); file_put_contents($file, '<?php'."\n". ''."\n". '$cache = ' . var_export($value, true) . ';'."\n". '?>'); return $value; }
function MakeDir($dir_name, $mode = 0777) { return tmkdir($dir_name, $mode); }
function download() { $this->CheckAdminPrivs('upgrade'); $upgrade_data_dir = DATA_PATH.'upgrade/'; is_dir($upgrade_data_dir) || @tmkdir($upgrade_data_dir); $tmp_file = $upgrade_data_dir."tttg.api.zip"; $tmp_exists = is_file($tmp_file); if($tmp_exists) { $tmp_md5 = md5_file($tmp_file); } $param = $_GET; unset($param['mod'], $param['code']); $url = 'admin.php?mod=upgrade_api&code=download'; foreach($param as $k=>$v) { $url .= '&' . $k . '=' . urlencode($v); } if(false == $tmp_exists || $tmp_md5 != get('file_md5')) { $data = $this->request('download', $param); if(!$data) { $this->Messager("请求失败,请稍候在试。",null); } $fp = fopen($tmp_file,"wb"); if($fp==false) { $this->Messager($tmp_file."文件无法写入",null); } $write_length=fwrite($fp, $data); fclose($fp); } if (false == file_exists($tmp_file)) { $this->Messager("升级包已经不存在,请重新下载", null); } $upgrade_tmp_dir = CACHE_PATH . '/tttg_api_tmp/'; is_dir($upgrade_tmp_dir) || @tmkdir($upgrade_tmp_dir); $files = logic('upgrade')->zip2web($tmp_file, $upgrade_tmp_dir); $error_found = logic('upgrade')->web2upgrade($upgrade_tmp_dir, ROOT_PATH); if ($error_found != 'ok') { $msg = '<div style="width:700px;text-align:left;">备份或者升级网站文件时出错,程序无法继续执行!<hr/>'; $msg .= $error_found; $msg .= '<hr/>请您检查相应文件权限后,<a href="'.$url.'">点击此处</a> 重新升级'; $msg .= '</div>'; $this->Messager($msg, null); } ini('settings.api_version', $param['version']); @unlink($tmp_file); logic('upgrade')->upgrade2finish(); $msg = "升级已经完成! "; $this->Messager($msg, 'admin.php?mod=api', 0); }
function SaveLog($sql, $filea, $line, $query_dir = './errorlog/') { if(!is_dir($query_dir))tmkdir($query_dir); $file = $query_dir . date('Y-m') . '.php'; if(!is_file($file)) { $create = fopen($file, 'w'); if($create) { fwrite($create, "<?php\r\n\$query=array();\r\n?>"); } fclose($create); } include($file); $query = (array)$query; $query_exists = array_filter($query, create_function('$var', 'return ($var["sql"]=="' . $sql . '");')); if($query_exists == false) { $query_string = array('time' => time(), 'sql' => $sql, 'file' => $filea, 'line' => $line, ); array_unshift($query, $query_string); $query = var_export($query, true); $query_str = "<?php\r\n\$query=$query;\r\n?>"; $fp = fopen($file, 'w'); if($fp) { fwrite($fp, $query_str); } fclose($fp); } }
function tmkdir($dir, $mode = 0777, $makeindex = false) { if(!is_dir($dir)) { clearstatcache(); tmkdir(dirname($dir)); @mkdir($dir, $mode); if(!empty($makeindex)) { $ret = @touch($dir.'/index.html'); @chmod($dir.'/index.html'); return $ret; } } return true; }
function install() { $this->CheckAdminPrivs('upgrade'); @set_time_limit(120); $version=$this->Post['version']?$this->Post['version']:$this->Get['version']; $step=$this->Get['step']; $status=(int)$this->Get['status']; if(empty($version))$this->Messager("参数错误"); $odver = get('odver') ? get('odver') : SYS_VERSION; $url="admin.php?mod=upgrade&code=install&version=$version&odver=$odver"; $upgrade_data_dir = DATA_PATH.'upgrade/'; $upcName = $odver.'~'.$version; $upgrade_file = $upgrade_data_dir.$upcName.".zip"; if (is_file($upgrade_file)==false) { $this->Messager("升级包已经不存在,请重新下载", null); } $upgrade_tmp_dir = $upgrade_data_dir.$odver.'~'.$version.'/'; is_dir($upgrade_tmp_dir) || @tmkdir($upgrade_tmp_dir); include_once(LIB_PATH.'io.han.php'); if($step=='check') { $quick = $this->Get['quick']; $check_url=$url."&step=check&quick={$quick}"; if($status===0) $this->Messager("正在释放临时文件...",$check_url.'&status=1',0); $files = logic('upgrade')->zip2web($upgrade_file, $upgrade_tmp_dir); isset($files['__extract_error__']) && $this->Messager($files['__error_string__'], null); $backup_url=$url."&step=backup"; if ($quick == 'yes') { $this->Messager('正在开始升级...', $backup_url, 0); } include handler('template')->file('@admin/upgrade_change_list'); exit; } if ($step=='backup') { logic('upgrade')->upgrade2start(); $original_path=ROOT_PATH; $backup_path=ROOT_PATH.'backup/'.SYS_VERSION.'-'.SYS_BUILD.'/'; if(!is_dir($backup_path)) { IoHandler::MakeDir($backup_path,0777); } clearstatcache(); $error_found = logic('upgrade')->web2backup($upgrade_tmp_dir, $backup_path); if ($error_found == 'ok') { $error_found = logic('upgrade')->web2upgrade($upgrade_tmp_dir, $original_path); } if ($error_found != 'ok') { $msg = '<div style="width:700px;text-align:left;">备份或者升级网站文件时出错,程序无法继续执行!<hr/>'; $msg .= $error_found; $msg .= '<hr/>请您检查相应文件权限后,<a href="'.$url.'&step=backup">点击此处</a> 重新升级'; $msg .= '</div>'; $this->Messager($msg, null); } $this->Messager("正在升级中,请勿关闭窗口...", $url, 0); } logic('upgrade')->upgrade2data($upgrade_tmp_dir); logic('upgrade')->upgrade2update($upgrade_tmp_dir, $original_path); logic('upgrade')->upgrade2clear($upcName); logic('upgrade')->upgrade2finish(); $msg="升级已经完成! <br/><br/><a href='admin.php?mod=index&code=home'>返回后台首页</a>"; $this->Messager($msg, null); }
function SaveLog($error_dir='./errorlog/') { if(!is_dir($error_dir))tmkdir($error_dir); $file=$error_dir.date('Y-m').'.php'; if(!is_file($file)) { $create=fopen($file,'w'); if($create) { fwrite($create,"<?php\r\n\$error=array();\r\n?>"); } fclose($create); } include($file); $error=(array)$error; $error_exists=array_filter($error,create_function('$var','return ($var["message"]=="'.$this->_message.'");')); if($error_exists==false) { $new_error=array('time'=>date("Y-m-d H:i:s"), 'type'=>$this->_type, 'file'=>$this->_file, 'line'=>$this->_line, 'sql'=>$this->_sql, 'message'=>$this->_message, 'username'=>MEMBER_NAME, 'ip'=>$_SERVER['REMOTE_ADDR'], 'uri'=>$_SERVER['REQUEST_URI'], 'method'=>$_SERVER['REQUEST_METHOD'], 'get'=>var_export($_GET,true), 'post'=>var_export($_POST,true), ); array_unshift($error,$new_error); $error=var_export($error,true); $error_str="<?php\r\n\$error=$error;\r\n?>"; $fp=fopen($file,'w'); if($fp) { fwrite($fp,$error_str); } fclose($fp); } }
private function MakePath($file) { $name = $file['name']; $ext = strtolower(@end(explode('.', $name))); list($s, $ms) = explode(' ', microtime()); $hash = md5($name.$s.$ms); $path = $this->savePath; $flag = array( '{$Y}', '{$M}', '{$D}', '{$EXT}', '{$HASH}' ); $flag_val = array( date('Y'), date('m'), date('d'), $ext, $hash ); $path = str_ireplace($flag, $flag_val, $path); tmkdir(dirname($path)); if ($this->Writeable($path)) { return $path; } return false; }
function MakeDir($dir_name, $mode = 0777) { $dir_name = str_replace("\\", "/", $dir_name); $dir_name = preg_replace("#(/"."/+)#", "/", $dir_name); return tmkdir($dir_name); }