Ejemplo n.º 1
0
 /**
  * 上传一个文件
  * 
  * @param $file 对应html中的一个html file控件
  * @param $path 存储路径
  * @param $seed 分级路径的种子,种子将被MD5后,从左至右每两位作为一级路径
  * @param $hashLevel 文件路径层级,将
  * @return unknown_type
  */
 public static function upload($file, $path, $allowType = '', $rename = true, $level = 0, $seed = null)
 {
     $ext = strtolower(self::getExt($file['name']));
     if (!empty($allowType) && strstr($allowType, $ext) === false) {
         throw new Hi_Tool_Exception("不上传允许的文件格式[{$ext}]");
     }
     if ($rename) {
         $name = time() . '_' . rand(10000, 99999) . '.' . $ext;
     } else {
         $name = $file['name'];
     }
     if ($seed) {
         $name = $seed . '_' . $name;
     }
     $path = Hi_Tool_Dir::standard($path);
     $level = intval($level);
     if ($level != 0) {
         $path = Hi_Tool_Dir::createByHash($path, 2, $seed);
     } else {
         Hi_Tool_Dir::create($path);
     }
     if (substr($path, -1) != DIRECTORY_SEPARATOR) {
         $path .= DIRECTORY_SEPARATOR;
     }
     $fp = $path . $name;
     copy($file['tmp_name'], $fp);
     return $fp;
 }
Ejemplo n.º 2
0
 /**
  * 检查目录是否存在,如果目录不存在且$autoCreate参数为true,创建该目录
  *
  * @param string $directory
  * @param bool $autoCreate
  * @return mix
  */
 public static function check($directory, $autoCreate = true)
 {
     if (is_dir($directory)) {
         return true;
     }
     if (!$autoCreate) {
         return false;
     }
     return Hi_Tool_Dir::create($directory);
 }
Ejemplo n.º 3
0
 /**
  * 初始化应用
  *
  * @param string $path
  */
 private function _setApp($path)
 {
     $this->_checkPath($path);
     $path .= DS;
     $cf = $path . 'config.xml';
     $config = new Hi_Config($cf);
     Hi_Store::set('config', $config);
     $classPath = $path . DS . 'class';
     Hi_Env::$PATH_APP = $path;
     Hi_Env::$PATH_CLASS = $classPath;
     $incPath = $classPath . PS . get_include_path();
     set_include_path($incPath);
     if (isset($config->timezone)) {
         date_default_timezone_set($config->timezone);
     }
     Hi_Env::$ENTRY_FILE = $_SERVER['SCRIPT_FILENAME'];
     Hi_Env::$APPID = $config->appid;
     Hi_Env::$DEBUG = (bool) $config->debug;
     Hi_Env::$DEBUG = $config->debug == 'on' || $config->debug == 'true';
     Hi_Env::$CACHEABLE = $config->cacheable != 'false' || !empty($config->cacheable);
     //设置全局的临时文件路径、缓存路径、日志路径
     $tmpPath = $config->tmp;
     if (empty($tmpPath)) {
         $tmpPath = sys_get_temp_dir();
     }
     $tmpPath = Hi_Tool_Dir::standard($tmpPath);
     if (substr($tmpPath, -1) != DS) {
         $tmpPath .= DS;
     }
     Hi_Env::$PATH_TMP = $tmpPath;
     $cachePath = $config->cache;
     if (empty($cachePath)) {
         $cachePath = $tmpPath . 'cache' . DS . Hi_Env::$APPID;
     }
     Hi_Tool_Dir::create($cachePath);
     Hi_Env::$PATH_CACHE = $cachePath;
     $logPath = $config->log;
     if (empty($logPath)) {
         $logPath = $tmpPath . 'logs';
     }
     Hi_Env::$PATH_LOG = $logPath;
 }
Ejemplo n.º 4
0
 protected function _setView()
 {
     if ($this->_view instanceof Hi_View) {
         return $this->_view;
     }
     $sc = $this->_config->smarty;
     if (empty($sc->template)) {
         $tplDir = Hi_Env::$PATH_APP . DS . 'templates';
     } else {
         $tplDir = $sc->template;
     }
     if (!is_dir($tplDir)) {
         throw new Hi_Exception('没有找到模板位置');
     }
     $this->_view = new Hi_View();
     $this->_view->template_dir = $tplDir;
     if (empty($sc->template_c) || !is_dir($sc->template_c)) {
         $this->_view->compile_dir = Hi_Env::$PATH_TMP . 'tempalte_c';
         Hi_Tool_Dir::create($this->_view->compile_dir);
     } else {
         $this->_view->template_c = $sc->template_c;
     }
     $this->_view->caching = (int) $sc->cache;
     $this->_view->debugging = $sc->debug == 'true' ? true : false;
     return $this->_view;
 }
Ejemplo n.º 5
0
 /**
  * 取$action对应的模板文件相对路径
  * 
  * @param string $action
  */
 protected function _tplRelativeFile($action)
 {
     $this->_setView();
     Hi_Tool_Dir::create($this->_view->template_dir . DS . $this->_subTplDir);
     return $this->_subTplDir . DS . $this->_table->getName() . '.' . $action . '.html';
 }