Esempio n. 1
0
 /**
  * 构造函数,初始化配置
  */
 private function __construct()
 {
     if (!empty(self::$FileLoader)) {
         return;
     }
     $this->day = date('Ymd', time());
     $this->dtime = date('Y-m-d H:i:s', time());
     self::$FileLoader = new FileLoader(PathGeneration::getFolder(".\\log\\") . "log_xqx_{$this->day}.log", null);
 }
Esempio n. 2
0
 protected function __construct()
 {
     $cachePath = PathGeneration::getFolder("./cache/kvdb/");
     $this->cacheFile = $cachePath . "local.tmp";
     if (is_readable($this->cacheFile)) {
         $this->data = json_decode(file_get_contents($this->cacheFile), true);
     } else {
         $this->data = array();
     }
 }
Esempio n. 3
0
 public static function append($path, $filename, &$context, $length = null)
 {
     $path = PathGeneration::getFolder($path);
     if (is_writable($path . $filename)) {
         $fp = fopen($path . $filename, "ab");
         if (fwrite($fp, $context, $length)) {
             return empty($length) ? strlen($context) : $length;
         }
     }
     return -1;
 }
Esempio n. 4
0
 /**
  * 缓存获取与设置结束,存入文件或者内存
  * @param null $cacheTime
  * @return bool
  */
 public function cacheSave($cacheTime = null)
 {
     if (isset($cacheTime) && !empty($cacheTime)) {
         $this->setCacheTime($cacheTime);
     }
     if ($this->ifGetByEcho) {
         // 获取输出缓冲数据
         $this->cacheContent = ob_get_contents();
         ob_end_flush();
     }
     // 更新内存中的缓存信息
     $this->cacheInfo[$this->cacheDigest]['expiredTime'] = $this->cacheTime;
     $this->cacheInfo[$this->cacheDigest]['expiredDateTime'] = date("Y-m-d H:i:s", $this->cacheTime);
     $ifSave = false;
     // 缓存文件地址
     $cacheContentFile = new FileLoader(PathGeneration::getFolder("{$this->cachePath}{$this->cacheId}") . "{$this->cacheDigest}.tmp", array("mode" => "write"));
     $cacheInfoFile = new FileLoader("{$this->cachePath}{$this->cacheId}_info.tmp", array("mode" => "write"));
     if ($cacheInfoFile->isWritable()) {
         if ($cacheContentFile->isWritable()) {
             $cacheInfoFile->write(json_encode($this->cacheInfo));
             $cacheContentFile->write($this->cacheContent);
             $cacheContentFile->close();
             $ifSave = true;
         }
         $cacheInfoFile->close();
     }
     return $ifSave;
 }
Esempio n. 5
0
 /**
  * 上传一张图片并保存为缩略图(丢弃原图)
  * @param string $fileField 表单名称
  * @param string $savePath 保存的路径,存放从[upload][rootPath]目录开始的文件夹
  * @param array $thumbArray 要生成的缩略图的信息,使用二维数组:[{'set':'big_image','width':135,'height':246}, ...]
  * @return array($stateInfo, $f) 返回一个成功信息和一个详细的内容(素材文件)
  */
 public function upImage($fileField, $savePath = null, $thumbArray)
 {
     $this->changeConfig($savePath);
     // 检查文件是否可以上传
     $info = isset($_FILES[$fileField]) ? $_FILES[$fileField] : null;
     $ifChecked = $this->checkFile($info);
     $stateInfo = $this->getStateInfo($ifChecked);
     if ($ifChecked === 0) {
         // 读取文件,开始生成压缩图
         import("GDImageDeal");
         $filename = $info["tmp_name"];
         if (is_readable($filename)) {
             $gdd = GDImageDeal::readImageByFilename($filename);
             foreach ($thumbArray as $value) {
                 $targetImage = $gdd->crop($value['width'], $value['height']);
                 $filePath = PathGeneration::getFolderAppendDateAndValue($this->config['savePath'], $value['set']);
                 $fileName = FileObject::fileNameByTime($info['ext']);
                 $targetImage->saveImage($filePath . $fileName);
                 //$targetImage->saveImage("cache/0.tmp");
                 //list($1,$2,$3)=FileObject::autoCreateByCopy($this->config['savePath'], $info['ext'], $info['tmp_name']);
                 // 纪录成功信息
                 $tf['width'] = $value['width'];
                 $tf['height'] = $value['height'];
                 $tf['savePath'] = $filePath;
                 $tf['filename'] = $fileName;
                 $tf['url'] = getConfig("site", "root") . $filePath . $fileName;
                 $info[] = $tf;
             }
         }
     }
     unset($info['tmp_name']);
     return array($stateInfo, $info);
 }