示例#1
0
 /**
  * uploadFromController
  *
  * @param AbstractSaveController $controller
  * @param string                 $field
  * @param DataInterface          $data
  * @param string                 $uri
  *
  * @return  boolean|string
  */
 public static function uploadFromController(AbstractSaveController $controller, $field, DataInterface $data, $uri)
 {
     // formControl is protected, we get it by TestHelper
     $base64 = $controller->input->post->getRaw('input-' . TestHelper::getValue($controller, 'formControl') . '-' . $field . '-data');
     $delete = $controller->input->post->get('input-' . TestHelper::getValue($controller, 'formControl') . '-' . $field . '-delete-image');
     if ($base64 && ($url = Base64Image::quickUpload($base64, $uri))) {
         $data->{$field} = $url;
         return $url;
     } elseif ($delete) {
         $data->{$field} = '';
         return true;
     }
     return false;
 }
示例#2
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;
 }