Example #1
0
 /**
  * 构造方法
  *
  * @param Monkey\App $app
  * @param mixed|null $config 配置
  */
 public function __construct($app, $config)
 {
     $this->app = $app;
     self::$dir = dir_format($app->DIR . (isset($config['sql_dir']) ? $config['sql_dir'] : '/logs/sql'));
     self::$dir .= '/' . date("Y-m-d", $app->TIME) . '/' . date("H", $app->TIME);
     $app->shutdown()->register(array($this, 'write'));
 }
Example #2
0
 /**
  * 数据库备份恢复工具
  * @param string $dataDir 存放数据库备份文件的目录
  * @param \PDO $pdo 数据库层管理器
  */
 public function __construct($dataDir, \PDO $pdo)
 {
     $dataDir = dir_format($dataDir);
     $this->dataDir = $dataDir;
     dir_check($dataDir);
     dir_check_writable($dataDir);
     $this->db = $pdo;
 }
Example #3
0
 /**
  * 用CURL模拟http、https、ftp、gopher、telnet、dict、file
  * 和ldap协议同其他网站通信
  * @param null|string $cookiePath cookie保存路径
  * @param null|string $proxy 代理设置
  * @param int $expire 时间限制
  */
 public function __construct($cookiePath = NULL, $proxy = null, $expire = 30)
 {
     if (is_null($cookiePath)) {
         $this->cookieFile = APP_PATH . '/temp/curl/curl.txt';
     } else {
         $cookiePath = dir_format($cookiePath);
         dir_check($cookiePath);
         $this->cookieFile = $cookiePath . '/curl.txt';
     }
     $this->proxy = $proxy;
     $this->expire = $expire;
 }
Example #4
0
 /**
  * @param Monkey\App $app
  */
 public function __construct($app)
 {
     $config = $app->config()->getComponentConfig('cache', 'file');
     $this->TIME = $app->TIME;
     $this->expire = $config['expire'];
     $this->cachePath = dir_format($app->TEMP . ($config['dir'] ? $config['dir'] : '/fileCache'));
     $this->cacheFile = $config['filename'] ? '/' . $config['filename'] : '/data';
     $this->cacheSize = $config['filesize'] ? $config['filesize'] : '15M';
     $this->dataOnCheck = $config['check'] ? $config['check'] : false;
     //是否验证数据
     if (!dir_check($this->cachePath)) {
         $this->error('缓存目录校验失败。');
     }
     $this->workat($this->cachePath . $this->cacheFile);
 }
Example #5
0
 private function uploadAction($index, $upName, $upSize, $upTmp, $upError, $saveDir, $saveName, $filterType = null, $maxSize = 0, $overwrite = false)
 {
     $saveDir = dir_format($saveDir);
     dir_check($saveDir);
     if (!is_uploaded_file($upTmp)) {
         return $this->notice(0, '这不是一个上传的文件!');
     }
     !is_int($maxSize) and $maxSize = size_to_bit($maxSize);
     if ($maxSize > 0 && $upSize > $maxSize) {
         return $this->notice(0, '文件超过指定的文件大小!');
     }
     switch ($upError) {
         case 0:
             break;
         case 1:
             $error = '文件超过服务器的约定大小';
             break;
         case 2:
             $error = '文件超过指定的文件大小!';
             break;
         case 3:
             $error = '文件只上传了部分!';
             break;
         case 4:
             $error = '文件上传失败!';
             break;
         default:
             $error = '未知错误!';
     }
     if (!empty($error)) {
         return $this->notice(0, $error);
     }
     $pathInfo = pathinfo($upName);
     $extension = $pathInfo['extension'];
     empty($saveName) and $saveName = substr($upName, 0, 0 - 1 - strlen($extension));
     $saveName = strtr($saveName, '.', '_');
     //消除因为apache配置失误造成的上传漏洞。
     $index and $saveName .= '_' . $index;
     $saveName .= '.' . strtolower($extension);
     $this->fileSystemCharset == 'GB2312' and $saveName = iconv("UTF-8", "GB2312//IGNORE", $saveName);
     $saveName = $saveDir . '/' . $saveName;
     if (!is_null($filterType)) {
         $types = explode('|', strtolower($filterType));
         if (!in_array($extension, $types)) {
             return $this->notice(0, '上传文件类型不在限定的文件类型之内!');
         }
         $upRealTypes = $this->getTypeOfReal($upTmp);
         $upRealTypes = explode('|', $upRealTypes);
         if (!in_array($extension, $upRealTypes)) {
             return $this->notice(0, '上传文件文件类型与其真实类型不一致,可能是修改了扩展名!');
         }
     }
     if (file_exists($saveName)) {
         if (!$overwrite) {
             return $this->notice(0, '要保存的文件名已存在,且不可覆盖!');
         } else {
             unlink($saveName);
         }
     }
     $result = move_uploaded_file($upTmp, $saveName);
     return $this->notice($result, $result ? $saveName : '未知错误,上传失败!');
 }
Example #6
0
/**
 * 将一个文件夹内容,复制或移动到另一个文件夹
 *
 * @param string $source 源文件夹名
 * @param string $target 目标文件夹
 * @param boolean $deleteSource 是否删除源文件夹(是则相当于移动,否则相当于复制)
 *
 * @return boolean
 */
function dir_copy($source, $target, $deleteSource = false)
{
    $source = dir_format($source);
    $target = dir_format($target);
    if ($source == $target) {
        return true;
    }
    if (!is_dir($source)) {
        return false;
    }
    dir_check($target);
    $handle = opendir($source);
    if (!$handle) {
        return false;
    }
    $sourcePath = $targetPath = '';
    while (($item = readdir($handle)) !== false) {
        if ($item == '.' || $item == '..') {
            continue;
        }
        $sourcePath = $source . '/' . $item;
        $targetPath = $target . '/' . $item;
        if (is_dir($sourcePath)) {
            dir_copy($sourcePath, $targetPath, $deleteSource);
            if ($deleteSource) {
                rmdir($sourcePath);
            }
        } else {
            copy($sourcePath, $targetPath);
            if ($deleteSource) {
                unlink($sourcePath);
            }
        }
    }
    closedir($handle);
    return true;
}
Example #7
0
 /**
  * 获取web方式请求的www根目录
  *
  * @return string
  */
 public function getDocumentRoot()
 {
     if ($this->documentRoot) {
         return $this->documentRoot;
     }
     //修复IIS服务器$_SERVER['DOCUMENT_ROOT']失效的情况
     if (!isset($_SERVER['DOCUMENT_ROOT'])) {
         if (isset($_SERVER['SCRIPT_FILENAME'])) {
             $_SERVER['DOCUMENT_ROOT'] = substr($_SERVER['SCRIPT_FILENAME'], 0, 0 - strlen($_SERVER['PHP_SELF']));
         } elseif (isset($_SERVER['PATH_TRANSLATED'])) {
             $_SERVER['DOCUMENT_ROOT'] = substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0 - strlen($_SERVER['PHP_SELF']));
         }
     }
     //修正DOCUMENT_ROOT末尾可能因为apache配置造成多余一个'/'。
     $_SERVER['DOCUMENT_ROOT'] = dir_format($_SERVER['DOCUMENT_ROOT']);
     $this->documentRoot = $_SERVER['DOCUMENT_ROOT'];
     return $this->documentRoot;
 }