Example #1
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);
 }