Exemplo n.º 1
0
 /**
  * @return string
  * @throws \yii\base\Exception
  */
 public function actionSaveImg()
 {
     $croppicForm = new CroppicForm();
     $croppicForm->file = UploadedFile::getInstanceByName('img');
     if ($croppicForm->file && $croppicForm->validate()) {
         $path = Cloud::getInst()->cloudPath;
         $pathWeb = Cloud::getInst()->webCloudPath;
         FileHelper::createDirectory($path);
         $croppicForm->file->name = uniqid('big_') . '.' . $croppicForm->file->extension;
         $croppicForm->file->saveAs($path . $croppicForm->file->baseName . '.' . $croppicForm->file->extension);
         list($width, $height) = getimagesize($path . $croppicForm->file->name);
         $json['status'] = 'success';
         $json['url'] = Url::to($pathWeb . $croppicForm->file->name, true);
         $json['width'] = $width;
         $json['height'] = $height;
         return Json::encode($json);
     }
     $json['status'] = 'error';
     $errors = $croppicForm->getFirstErrors();
     if ($errors) {
         $json['message'] = reset($errors);
     } else {
         $json['message'] = 'Oops, something went wrong. Please try again!';
     }
     return Json::encode($json);
 }
 /**
  * @return string
  */
 public function actionUpload()
 {
     /* @var Cloud*/
     $cloud = Cloud::getInst();
     $path = $cloud->storage->getPath();
     $uploader = new UploadHandler();
     FileHelper::createDirectory($path);
     // Specify the list of valid extensions, ex. array("jpeg", "xml", "bmp")
     $uploader->allowedExtensions = [];
     // all files types allowed by default
     // Specify max file size in bytes.
     $uploader->sizeLimit = 20 * 1024 * 1024;
     // default is 10 MiB
     $method = Yii::$app->request->getMethod();
     if ($method == "POST") {
         // Assumes you have a chunking.success.endpoint set to point here with a query parameter of "done".
         // For example: /myserver/handlers/endpoint.php?done
         if (isset($_GET["done"])) {
             $result = $uploader->combineChunks($path);
         } else {
             // Call handleUpload() with the name of the folder, relative to PHP's getcwd()
             $result = $uploader->handleUpload($path, uniqid());
             // To return a name used for uploaded file you can use the following line.
             $result["uploadName"] = $uploader->getUploadName();
         }
         return Json::encode($result);
     } else {
         if ($method == "DELETE") {
             $result = $uploader->handleDelete($path);
             return Json::encode($result);
         }
     }
 }
Exemplo n.º 3
0
 public function init()
 {
     $this->sizeLimit = $this->toBytes(ini_get('upload_max_filesize'));
     if ($this->chunksFolder === null) {
         $this->chunksFolder = Cloud::getInst()->cloudPath . 'chunks';
     }
     parent::init();
 }
Exemplo n.º 4
0
 public function init()
 {
     parent::init();
     Cloud::getInst();
     if (empty($this->name)) {
         throw new InvalidConfigException('The "name" property must be set.');
     }
     $this->options['id'] = ArrayHelper::remove($this->options, 'id', $this->getId());
     echo Html::script($this->getTemplate(), ['type' => 'text/template', 'id' => 'qq-template-gallery-' . $this->getId()]);
     echo Html::tag('div', null, $this->options);
     if ($this->filesPath && $this->filesUrlPath) {
         $this->registerScript(true);
         echo $this->showSavedFiles();
     } else {
         $this->registerScript();
     }
 }
Exemplo n.º 5
0
 /**
  * @return string
  */
 public function getWebPath()
 {
     return Cloud::getInst()->webCloudPath . $this->getId() . '/';
 }