コード例 #1
0
 /**
  * @return string
  * @throws \yii\base\Exception
  */
 public function actionCropImg()
 {
     $path = Cloud::getInstance()->cloudPath;
     $pathWeb = Cloud::getInstance()->webCloudPath;
     FileHelper::createDirectory($path);
     $filename = basename(Yii::$app->request->post('imgUrl'));
     // original sizes
     $imgInitW = Yii::$app->request->post('imgInitW');
     $imgInitH = Yii::$app->request->post('imgInitH');
     // resized sizes
     $imgW = Yii::$app->request->post('imgW');
     $imgH = Yii::$app->request->post('imgH');
     // offsets
     $imgX1 = Yii::$app->request->post('imgX1');
     $imgY1 = Yii::$app->request->post('imgY1');
     // crop box
     $cropW = Yii::$app->request->post('cropW');
     $cropH = Yii::$app->request->post('cropH');
     // rotation angle
     $angle = Yii::$app->request->post('rotation');
     $originalImage = Image::getImagine()->open($path . $filename);
     $cropFilename = strtr($filename, ['big_' => 'crop_']);
     $originalImage->resize(new Box($imgW, $imgH))->rotate($angle)->crop(new Point($imgX1, $imgY1), new Box($cropW, $cropH));
     $originalImage->save($path . $cropFilename);
     if (strpos($filename, 'big_') === 0) {
         unlink($path . $filename);
     }
     $json['status'] = 'success';
     $json['url'] = Url::to($pathWeb . $cropFilename, true);
     return Json::encode($json);
 }
コード例 #2
0
 /**
  * @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);
         }
     }
 }
コード例 #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();
 }
コード例 #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();
     }
 }
コード例 #5
0
ファイル: Storage.php プロジェクト: pavlinter/yii2-app-core
 /**
  * @return string
  */
 public function getWebPath()
 {
     return Cloud::getInst()->webCloudPath . $this->getId() . '/';
 }