/**
* 创建记日志目录
* @param undefined $path
*
* @return
*/
public static function creatDir($path){
$arr = explode('/',$path);
$pathStr = '';
if($arr){
foreach($arr as $val){
$pathStr .= $val.'/';
if(!to8to_is_dir($pathStr)){
to8to_mkdir($pathStr);
}
}
}
}
<?php
include_once(ROOT.'/gb_php/to8tocurl.class.php');
/**
* @param $path 文件路径
* @param $method 请求方式
* @return 返回请求数组
* 连接有效服务器
*/
function to8to_file_server($path,$method='get')
{
global $_CFG;
$serverconf = $_CFG['fileServer'];
if(empty($serverconf))
{
//throw new Exception('连接不上');
}
$curl = new to8toCurl();
foreach($serverconf as $val)
{
$recurl = $curl->curl($val,$path,$method);
if($recurl['httpCode'] == 200)
{
return $recurl;
}
}
}
//获取文件修改时间
function to8to_filemtime($path)
{ checkRoot($path);
if(defined('FILE_SERVER') && strstr($path,ROOT.'/pic/')!==false)
{
$redata=to8to_file_server(array('act'=>'getInfo','path'=>$path),'get');
$data = json_decode($redata['data'],true);
$time = $data["utime"]?$data["utime"]:false;
}
else
{
$time = filemtime($path);
}
return $time;
}
//获取文件是否存在
function to8to_is_file($path)
{ checkRoot($path);
if(defined('FILE_SERVER') && strstr($path,ROOT.'/pic/')!==false)
{
$redata=to8to_file_server(array('act'=>'getInfo','path'=>$path),'get');
$data = json_decode($redata['data'],true);
$is_file = $data["file_exists"];
$is_file = $is_file ? ($data["filetype"]==0?true:false) : false;
}
else
{
$is_file = is_file($path);
}
return $is_file;
}
/**
* @param $path
* @return bool
* 文件是否存在
*/
function to8to_file_exists($path)
{ checkRoot($path);
if(defined('FILE_SERVER') && strstr($path,ROOT.'/pic/')!==false)
{
$redata=to8to_file_server(array('act'=>'getInfo','path'=>$path),'get');
$data = json_decode($redata['data'],true);
$file_exists = $data["file_exists"] ;
}
else
{
$file_exists = file_exists($path);
}
return $file_exists;
}
/**
* @param $path
* @return bool
* 是否是文件目录
*/
function to8to_is_dir($path)
{ checkRoot($path);
if(defined('FILE_SERVER') && strstr($path,ROOT.'/pic/')!==false)
{
$redata=to8to_file_server(array('act'=>'getInfo','path'=>$path),'get');
$data = json_decode($redata['data'],true);
$is_dir = $data["file_exists"];
$is_dir = $is_dir ? ($data['filetype']==1?true:false):false;
}
else
{
$is_dir = is_dir($path);
}
return $is_dir;
}
/**
* @param $tmpName
* @param $toPath
* @return bool
*/
function to8to_move_uploaded_file($tmpName , $toPath)
{ checkRoot($toPath);
$newExt = substr(strrchr($toPath,'.'),1);
if(strtolower($newExt) == 'php' || strtolower($newExt) =='php5')
{
return false;
}
$returnstr = move_uploaded_file($tmpName , $toPath);
if(defined('FILE_SERVER')&& strstr($toPath,ROOT.'/pic/')!==false)
{
$redata=to8to_file_server(array('act'=>'upInfo','path'=>$toPath),'get');
}
return $returnstr;
}
/**
* 创建目录
* @return bool
* @author yaowenqiang
*/
function to8to_mkdir($pathname,$mode = 0777,$recursive = false )
{
return mkdir($pathname,$mode,$recursive);
}
/**
* 清空状态缓存
*
* @return void
* @author yaowenqiang
*/
function to8to_clearstatcache()
{
clearstatcache();
}
/**
* 文件拷贝
*
* @return bool
* @author yaowenqiang
*/
function to8to_copy($source,$dest)
{
return copy($source,$dest);
}
/**
* 删除文件
*
* @return bool
* @author yaowenqiang
*/
function to8to_delete($filename)
{
return unlink($filename);
}
/**
* 删除文件
*
* @return bool
* @author yaowenqiang
*/
function to8to_unlink($filename)
{ checkRoot($filename);
return unlink($filename);
}
/**
* 关闭文件
*
* @return bool
* @author yaowenqiang
*/
function to8to_fclose($handle)
{
return fclose($handle);
}
/**
* 测试文件指针是否到了文件结束的位置
*
* @return bool
* @author yaowenqiang
*/
function to8to_feof($handle)
{
return feof($handle);
}
/**
* 从文件指针中读取字符
*
* @return string
* @author yaowenqiang
*/
function to8to_fgetc($handle)
{
return fgetc($handle);
}
/**
* 从文件指针中读入一行并解析 CSV 字段
*
* @return array
* @author yaowenqiang
*/
function to8to_fgetcsv($handle,$length=0,$delimiter=',',$enclosure='"',$escape='\\')
{
return fgetcsv($handle,$length,$delimiter,$enclosure,$escape);
}
/**
* 从文件指针中读取一行
*
* @return void
* @author yaowenqiang
*/
function to8to_fgets($handle,$length=0)
{
if($length>0)
{
return fgets($handle,$length);
}
return fgets($handle);
}
/**
* 从文件指针中读取一行并过滤掉 HTML 标记
*
* @return string
* @author yaowenqiang
*/
function to8to_fgetss($handle,$length=0,$allowable_tags='')
{ if($length>0)
{
return fgetss($handle,$length,$allowable_tags);
}
return fgetss($handle);
}
/**
* 取得文件类型
*
* @return string
* @author yaowenqiang
*/
function to8to_filetype($filename)
{ checkRoot($filename);
return filetype($filename);
}
/**
* 轻便的咨询文件锁定
*
* @return string
* @author yaowenqiang
*/
function to8to_flock($handle,$operation,$wouldblock=true)
{
return flock($handle,$operation,$wouldblock);
}
/**
* 打开文件或者 URL
*
* @return string
* @author yaowenqiang
*/
function to8to_fopen($filename, $mode, $use_include_path = false, $context = null)
{ checkRoot($filename);
if (!$filename || preg_match("/\.\./", $filename)) {
/*日志记录路径*/
$logName = ROOT.'/syslog/mingxilog/filePathCheck'.date("Y-m-d").'.log';
$f = fopen($logName, 'a');
$fun_msg = debug_backtrace();
$log = '[含点点]'.date('H:i:s').json_encode($fun_msg);
fwrite($f, $log."\n");
fclose($f);
}
if ($context == null) {
return fopen($filename, $mode, $use_include_path);
} else {
return fopen($filename, $mode, $use_include_path, $context);
}
}
/**
* 输出文件指针处的所有剩余数据
*
* @return string
* @author yaowenqiang
*/
function to8to_fpassthru($handle)
{
return fpassthru($handle);
}
/**
* 将行格式化为 CSV 并写入文件指针
*
* @return string
* @author yaowenqiang
*/
function to8to_fputcsv($handle,$fields,$delimiter=',',$enclosure='"')
{
return fputcsv($handle,$fields,$delimiter,$enclosure);
}
/**
* 将行格式化为 CSV 并写入文件指针
*
* @return string
* @author yaowenqiang
*/
function to8to_fputs($file,$string,$length=0)
{
if($length>0)
{
return fputs($file,$string,$length);
}
return fputs($file,$string);
}
/**
* 读取文件(可安全用于二进制文件)
*
* @return string
* @author yaowenqiang
*/
function to8to_fread($handle,$length)
{
return fread($handle,$length);
}
/**
* 从文件中格式化输入
*
* @return string
* @author yaowenqiang
*/
function to8to_fscanf($handle,$length)
{
return fscanf($handle,$length);
}
/**
* 通过已打开的文件指针取得文件信息
*
* @return string
* @author yaowenqiang
*/
function to8to_fstat($handle)
{
return fstat($handle);
}
/**
* 写入文件(可安全用于二进制文件)
*
* @return int
* @author yaowenqiang
*/
function to8to_fwrite($handle,$string,$length=0)
{ if($length>0)
{
return fwrite($handle,$string,$length);
}
return fwrite($handle,$string);
}
/**
* 将文件截断到给定的长度
*
* @return bool
* @author yaowenqiang
*/
function to8to_ftruncate($handle,$size)
{
return ftruncate($handle,$size);
}
/**
* 寻找与模式匹配的文件路径
*
* @return array
* @author yaowenqiang
*/
function to8to_glob($pattern,$flag=0)
{
return glob($pattern,$flag);
}
/**
* 判断给定文件名是否为一个符号连接
*
* @return bool
* @author yaowenqiang
*/
function to8to_is_link($filename)
{ checkRoot($filename);
return is_link($filename);
}
/**
* 判断给定的文件名是否可写
*
* @return bool
* @author yaowenqiang
*/
function to8to_is_writable($filename)
{ checkRoot($filename);
return is_writable($filename);
}
/**
* 判断给定文件名是否可读
*
* @return bool
* @author yaowenqiang
*/
function to8to_is_readable($filename)
{ checkRoot($filename);
return is_readable($filename);
}
/**
* 判断文件是否是通过 HTTP POST 上传的
*
* @return bool
* @author yaowenqiang
*/
function to8to_is_uploaed_file($filename)
{ checkRoot($filename);
return is_uploaed_file($filename);
}
/**
* 输出一个文件
*
* @return bool
* @author yaowenqiang
*/
function to8to_readfile($filename,$include_path=false,$context='')
{ checkRoot($filename);
return readfile($filename);
}
/**
* 返回规范化的绝对路径名
*
* @return string
* @author yaowenqiang
*/
function to8to_realpath($path)
{ checkRoot($path);
return realpath($path);
}
/**
* 重命名一个文件或目录
*
* @return bool
* @author yaowenqiang
*/
function to8to_rename($oldname,$newname)
{
return rename($oldname,$newname);
}
/**
* 倒回文件指针的位置
*
* @return bool
* @author yaowenqiang
*/
function to8to_rewind($handle)
{
return rewind($handle);
}
/**
* 删除目录
*
* @return bool
* @author yaowenqiang
*/
function to8to_rmdir($dirname)
{
return rmdir($dirname);
}
/**
* 建立一个临时文件
*
* @return resource
* @author yaowenqiang
*/
function to8to_tmpfile()
{
return tmpfile();
}
/**
* 设定文件的访问和修改时间
*
* @return resource
* @author yaowenqiang
*/
function to8to_touch($filename,$time=0,$atime=0)
{ checkRoot($filename);
if($time>0||$atime>0)
{ if($time<=0)
{
$time = time();
}
if($atime<=0)
{
$atime = time();
}
return touch($filename,$time,$atime);
}
return touch($filename);
}
/**
* 设定文件的访问和修改时间
*
* @return resource
* @author yaowenqiang
*/
function to8to_umask($mask=0777)
{
return umask($mask);
}
/*函数返回文件路径的部分
* @author wong
* @parm string string
* @return filename
*/
function to8to_basename($path,$suffix='')
{
return basename($path);
}
/*函数文件所属组
*@author wong
*@return bool
* */
function to8to_chgrp($file,$group)
{
return chgrp($file,$group);
}
/*函数改变文件的模式
* @author wong
* @return bool
* */
function to8to_chomd($file,$mod=0755)
{
return chmod($file,$mod);
}
/*函数改变文件所有者
* @author wong
* @return bool
* */
function to8to_chown($file,$user)
{
return chown($file,$user);
}
/*函数返回文件目录部分
* @author wong
* @return bool
* */
function to8to_dirname($path)
{
return dirname($path);
}
/*函数返回目录可用空间
* @author wong
* @return bool
* */
function to8to_disk_free_space($directory)
{
return disk_free_space($directory);
}
/* 函数将缓冲内容输出到文件
* @author wong
* @return bool
* */
function to8to_fflush($file)
{
return fflush($file);
}
/*函数返回一个目录磁盘总大小
* @author wong
* @return bool
* */
function to8to_diskfreespace($directory)
{
return diskfreespace($directory);
}
/**
* 自己封装的_file_put_contents函数
* 对写入的文件后缀做了限制
* @param $filename
* @param $data
* @param null $flags
* @param null $context
* @return int|string
*/
function to8to_file_put_contents($filename, $data, $flags = null, $context = null)
{
$ext = getFileExt($filename);
if (!$filename || $ext == 'php')
{
return '';
}
return file_put_contents($filename, $data, $flags, $context);
}
/**
* 自己封装的_file_get_contents函数
* 主要对一些file://协议做了过滤
* @param $filename
* @param null $flags
* @param null $context
* @param null $offset
* @param null $maxlen
* @return string
*/
function to8to_file_get_contents($filename, $flags = null, $context = null, $offset = null, $maxlen = null)
{
if (!$filename || preg_match("/(\.\.|file:\/\/)/", $filename)) {
return '';
}
if ($maxlen === null) {
return file_get_contents($filename, $flags, $context, $offset);
} else {
return file_get_contents($filename, $flags, $context, $offset, $maxlen);
}
}
/*函数返回文件上次访问时间
* @author wong
* @return int
* */
function to8to_fileatime($filename)
{
return fileatime($filename);
}
/*函数返回文件修改时间
* @author wong
* @return int
* */
function to8to_filectime($filename)
{
return filectime($filename);
}
/*函数返回文件组ID
* @author wong
* @return int
* */
function to8to_filegroup($filename)
{
return filegroup($filename);
}
/*函数返回文件inode编号
* @author wong
* @return int bool
* */
function to8to_fileinode($filename)
{
return fileinode($filename);
}
/*函数返回文件的所有者
* @author wong
* @author int
* */
function to8to_fileowner($filename)
{
return fileowner($filename);
}
/*函数返回文件或目录的权限
* @author wong
* @return int
* */
function to8to_fileperms($filename)
{
return fileperms($filename);
}
/*函数返回文件大小
* @author wong
* @return int
* */
function to8to_filesize($filename)
{
return filesize($filename);
}
/*函数返回文件大小
* @author wong
* @return int
* */
function to8to_fnmatch($pattern,$string,$flags=0)
{
return fnmatch($pattern,$string,$flags);
}
/*函数检查制定的文件是否可执行
* @author wong
* @return bool
* */
function to8to_is_executable($file)
{
return is_executable($file);
}
/*函数改变文件所属组
* @author wong
* @return bool
* */
function to8to_ichgrp($file,$group)
{
return ichgrp($file,$group);
}
/*函数创建一个硬连接
* @author wong
* @return bool
* */
function to8to_link($target,$link)
{
return link($target,$link);
}
/*函数返回连接的信息
* @author wong
* @author int
* */
function to8to_linkinfo($path)
{
return linkinfo($path);
}
/*函数解析一个配置文件,并以数组的形式返回其中的设置
* @author wong
* @return array
* */
function to8to_parse_ini_file($file,$process_sections=true)
{
return parse_ini_file($file,$process_sections);
}
/*
* @author wong
* @return array
* */
function to8to_parse_ini_string($ini,$process_sections=false,$scanner_mode=INI_SCANNER_NORMAL)
{
return parse_ini_string($ini,$process_sections,$scanner_mode);
}
/*函数关闭有popen()打开的管道
* @author wong
* @return int
* */
function to8to_pclose($pipe)
{
return pclose($pipe);
}
/*函数打开进程文件指针
* @author wong
* @return resource
* */
function to8to_popen($command,$mode)
{
// return popen($command,$mode);
}
/*函数返回符号连接指向的目标
* @author wong
* @return string
* */
function to8to_readlink($linkPath)
{
return readlink($linkPath);
}
/*
* @author wong
* @return init
* */
function to8to_realpath_cache_size()
{
return realpath_cache_size();
}
/*返回规范化的绝对路径
* @author wong
* @return array
* */
function to8to_realpath_cache_get()
{
return realpath_cache_get();
}
/*返回关于文件的信息
* @author wong
* @return string
* */
function to8to_stat($file)
{
return stat($file);
}
/*返回函数设置打开文件缓冲大小
* @author wong
* @return int
* */
function to8to_set_file_buffer($file,$buffer)
{
return set_file_buffer($file,$buffer);
}
/*创建符号连接
* @author wong
* @return bool
* */
function to8to_symlink($target,$link)
{
return symlink($target,$link);
}
/*函数创建具有唯一文件名的临时文件
* @author wong
* @return strimg
* */
function to8to_tempnam($target,$link)
{
return tempnam($target,$link);
}
/*函数(w+)创建具有唯一文件名的临时文件
* @author wong
* @return string
* */
function to8to_tempfile($target,$link)
{
return tmpfile($target,$link);
}
/*函数读取一个
* @author wong
* @return string
* */
function to8to_file($path,$inclue_path=0,$context=null)
{
return file($path,$inclue_path,$context);
}
/*检查是否存在是否为ROOT开头,不是则记录日志
* $path string
* */
function checkRoot($path)
{
if ( strstr($path,ROOT)==false)
{
/*日志记录路径*/
$logName = ROOT.'/syslog/mingxilog/filePathCheck'.date("Y-m-d").'.log';
$f = fopen($logName, 'a');
$fun_msg = debug_backtrace();
$fun_msg = is_array($fun_msg)?$fun_msg:array();
$log = '[路径非ROOT开头]'.date('H:i:s').json_encode($fun_msg);
fwrite($f, $log."\n");
fclose($f);
}
}