/** * Creates a new Books model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Book(); if ($model->load(Yii::$app->request->post())) { $model->fileImage = UploadedFile::getInstance($model, 'fileImage'); if ($model->fileImage != null) { $imageName = Yii::$app->security->generateRandomString(); $model->preview = $imageName . '.' . $model->fileImage->extension; } $model->save(); if ($model->fileImage != null) { $model->upload($imageName); } return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model]); } }