/** * @return mixed */ public function renderGridBox() { $fileThumb = Filemanager::getThumbnail($this->fileType, $this->src, "{$this->thumbnailSize[0]}px", "{$this->thumbnailSize[1]}px"); $toolbox = $this->renderToolbox(); $hoverWrapper = Html::tag('div', '', ['class' => 'hover-wrapper']); if (isset($this->owner->model)) { $this->alt_text = isset($this->owner->model->file_id) ? \evneandreys\filemanager\models\Files::findOne($this->owner->model->file_id)->alt_text : false; } return Html::tag('div', $fileThumb . $hoverWrapper . $toolbox, ['class' => 'fm-section-item', 'data-name' => $this->alt_text]); }
/** * @return array|void */ public function actionUpload() { FilemanagerAsset::register($this->view); $model = new $this->module->models['files'](); $model->scenario = 'upload'; $folders = $this->module->models['folders']; $folderArray = ArrayHelper::map($folders::find()->all(), 'folder_id', 'category'); if (Yii::$app->request->isAjax) { if (!in_array(Yii::$app->request->post('uploadType'), [Filemanager::TYPE_FULL_PAGE, Filemanager::TYPE_MODAL])) { echo Json::encode(['error' => Yii::t('filemanager', 'Invalid value: {variable}', ['variable' => 'uploadType'])]); \Yii::$app->end(); } Yii::$app->response->getHeaders()->set('Vary', 'Accept'); $file = UploadedFile::getInstances($model, 'upload_file'); if (!$file) { echo Json::encode(['error' => Yii::t('filemanager', 'File not found.')]); \Yii::$app->end(); } $model->folder_id = Yii::$app->request->post('uploadTo'); $folder = $folders::find()->select(['path', 'storage'])->where('folder_id=:folder_id', [':folder_id' => $model->folder_id])->one(); if (!$folder) { echo Json::encode(['error' => Yii::t('filemanager', 'Invalid folder location.')]); \Yii::$app->end(); } $uploadStatus = true; $model->upload_file = $file[0]; $model->filename = $file[0]->name; list($width, $height) = getimagesize($file[0]->tempName); $model->dimension = $width && $height ? $width . 'X' . $height : null; // Too large size will cause memory exhausted issue when create thumbnail if (!is_null($model->dimension)) { if ($width > 2272 || $height > 1704) { echo Json::encode(['error' => Yii::t('filemanager', 'File dimension at most 2272 X 1704.')]); \Yii::$app->end(); } } $model->mime_type = $file[0]->type; $model->url = $folder->path; $extension = '.' . $file[0]->getExtension(); if (isset($this->module->storage['s3'])) { $model->object_url = '/'; $model->host = isset($this->module->storage['s3']['host']) ? $this->module->storage['s3']['host'] : null; $model->storage_id = $this->module->storage['s3']['bucket']; $this->saveModel($model, $extension, $folder->storage); $uploadStatus = $this->uploadToS3($model, $file[0], $extension); } else { $model->object_url = '/' . $folder->path . '/'; $model->storage_id = $this->module->directory; $this->saveModel($model, $extension, $folder->storage); $uploadStatus = $this->uploadToLocal($model, $file[0], $extension); } if (!$uploadStatus) { echo Json::encode(['error' => Yii::t('filemanager', 'Upload fail due to some reasons.')]); \Yii::$app->end(); } // if upload type = 1, render edit bar below file input container // if upload type = 2, switch active tab to Library for user to select file Yii::$app->response->format = Response::FORMAT_JSON; if (Yii::$app->request->post('uploadType') == Filemanager::TYPE_FULL_PAGE) { $fileType = $model->mime_type; if ($model->dimension) { $fileType = 'image'; } $html = Filemanager::renderEditUploadedBar($model->file_id, $model->object_url, $model->src_file_name, $fileType); return ['status' => 1, 'message' => 'Upload Success', 'type' => Yii::$app->request->post('uploadType'), 'html' => $html]; } else { return ['status' => 1, 'message' => 'Upload Success', 'type' => Yii::$app->request->post('uploadType')]; } return; } $multiple = false; $maxFileCount = 0; if ($this->module->filesUpload['multiple'] != false) { $multiple = true; $maxFileCount = isset($this->module->filesUpload['maxFileCount']) ? $this->module->filesUpload['maxFileCount'] : 0; } return $this->render('upload', ['model' => $model, 'folderArray' => $folderArray, 'multiple' => $multiple, 'maxFileCount' => $maxFileCount]); }