/** * Creates a new MarketingImage model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new MarketingImage(); $model->scenario = 'create'; if ($model->load(Yii::$app->request->post())) { $imageName = $model->marketing_image_name; $model->file = UploadedFile::getInstance($model, 'file'); $fileName = 'uploads/' . $imageName . '.' . $model->file->extension; $fileName = preg_replace('/\\s+/', '', $fileName); $thumbName = 'uploads/' . 'thumbnail/' . $imageName . 'thumb.' . $model->file->extension; $thumbName = preg_replace('/\\s+/', '', $thumbName); $model->marketing_image_path = $fileName; $model->marketing_thumb_path = $thumbName; $model->save(); $model->file->saveAs($fileName); Image::thumbnail($fileName, 60, 60)->save($thumbName, ['quality' => 50]); return $this->redirect(['view', 'id' => $model->id, 'model' => $model]); } else { return $this->render('create', ['model' => $model]); } }