示例#1
0
文件: Base.php 项目: ZhuJingfa/HuiLib
 /**
  * 生成一个新文件的储存路径
  */
 protected function getNewFilePath($meta)
 {
     if (empty($meta['size']) || empty($meta['type']) || empty($meta['name'])) {
         throw new Exception(Front::getInstance()->getHuiLang()->_('cdn.upload.files.error'));
     }
     $config = $this->getConfig();
     $miniHash = 24;
     if ($config['hash_length'] < $miniHash) {
         throw new Exception(Front::getInstance()->getHuiLang()->_('cdn.upload.hash_length.error', $miniHash));
     }
     $miniDepth = 0;
     $maxDepth = 5;
     if ($config['directory_depth'] < $miniDepth || $config['directory_depth'] > $maxDepth) {
         throw new Exception(Front::getInstance()->getHuiLang()->_('cdn.upload.directory_depth.error', $miniDepth, $maxDepth));
     }
     $hash = \HuiLib\Helper\Utility::geneRandomHash($config['hash_length']);
     $type = Param::post('type', Param::TYPE_STRING);
     $filePath = $config['save_path'] . $type . SEP . date('Y') . SEP;
     //每级包含的字母
     $charPerStep = 2;
     for ($iter = 0; $iter < $config['directory_depth']; $iter++) {
         $filePath .= substr($hash, $iter * $charPerStep, $charPerStep) . SEP;
     }
     //创建目录
     if (!is_dir($filePath)) {
         mkdir($filePath, 0777, TRUE);
     }
     $ext = $this->getExt($meta['name']);
     $file = $filePath . substr($hash, $iter * $charPerStep) . $ext;
     $result = array();
     $result['file'] = $file;
     $result['url'] = str_ireplace(SEP, URL_SEP, str_ireplace($config['save_path'], '', $file));
     return $result;
 }
示例#2
0
 /**
  * 初始化一个Session
  * 
  * 每次session访问均有open操作
  * 1、更新用户session最后活跃时间
  * 2、到期前7天内活跃需延长用户Passport cookie生命期,session储存键的生命期
  * 
  * @see \SessionHandlerInterface::open()
  */
 public function open($savePath, $name)
 {
     //初始化,设置个性化40位SessionID
     if (session_id() == '') {
         //自定义规则生成session_id的方案,必须在session_open中调用有效
         $sessionId = \HuiLib\Helper\Utility::geneRandomHash();
         if ($this->read($sessionId)) {
             //session存在
             $sessionId = \HuiLib\Helper\Utility::geneRandomHash();
             //再尝试生成一次
         }
         session_id($sessionId);
     }
     //更新session管理器最后活跃
     if ($this->manager->getModel()) {
         $this->manager->update(session_id());
     }
     return true;
 }
示例#3
0
 private function test()
 {
     echo Utility::geneRandomHash() . PHP_EOL;
     echo Utility::genUuid();
 }
示例#4
0
 /**
  * 生成安全校验码
  */
 protected function geneState()
 {
     $_SESSION['tmpOpenConnectState'] = Utility::geneRandomHash(32);
     return $_SESSION['tmpOpenConnectState'];
 }