示例#1
0
 /**
  * doAjax
  *
  * @return  mixed
  */
 protected function doExecute()
 {
     if (!$this->app->get('unidev.image.storage')) {
         throw new \LogicException('No image storage set in config.');
     }
     $file = $this->input->files->get($this->fieldName);
     $folder = $this->input->getPath('folder');
     $folder = ltrim($folder . '/', '/');
     if ($file->getError()) {
         throw new \RuntimeException('Upload fail: ' . UploadedFileHelper::getUploadMessage($file->getError()), 500);
     }
     $id = $this->getImageName($file->getClientFilename());
     $temp = $this->getImageTemp($id, File::getExtension($file->getClientFilename()));
     if (!is_dir(dirname($temp))) {
         Folder::create(dirname($temp));
     }
     $file->moveTo($temp);
     $temp = $this->resize($temp);
     if (!is_file($temp)) {
         throw new \RuntimeException('Temp file not exists');
     }
     $url = ImageUploader::upload($temp, $this->getImagePath($folder . $id, File::getExtension($temp)));
     File::delete($temp);
     $this->addMessage('Upload success.');
     return array('url' => $url);
 }
示例#2
0
 /**
  * Get remote url.
  *
  * @param   mixed $identify The identify of this file or item.
  *
  * @return  string  Identify URL.
  */
 public static function getRemoteUrl($identify)
 {
     return ImageUploader::getAdapter()->getHost() . '/' . static::getPath($identify);
 }
示例#3
0
 /**
  * quickUpload
  *
  * @param   string  $base64
  * @param   string  $uri
  *
  * @return  string
  */
 public static function quickUpload($base64, $uri)
 {
     $ext = Base64Image::getTypeFromBase64($base64);
     if (!$ext) {
         return false;
     }
     $temp = WINDWALKER_TEMP . '/unidev/images/temp/' . gmdate('Ymd') . '/' . md5(uniqid(mt_rand(1, 999))) . '.' . $ext;
     if (!is_dir(dirname($temp))) {
         Folder::create(dirname($temp));
     }
     Base64Image::toFile($base64, $temp);
     // Upload to Cloud
     $url = ImageUploader::upload($temp, $uri);
     if (is_file($temp)) {
         File::delete($temp);
     }
     return $url;
 }