public function actionCreateFile() { $request = Yii::$app->request; $filePost = $request->post('File'); $fileDirectory = FileDirectory::findOne((int) $filePost['file_directory_id']); $model = new FileList(); $model->attachBehavior('FileSave', ['class' => FileMoveBehavior::className(), 'directoryPath' => $fileDirectory->path]); if ($filePost !== null) { $headers = Yii::$app->response->headers; $model->attributes = $filePost; $model->file_directory_id = $fileDirectory->id; if ($model->save()) { $headers->add('HTTP/1.1 201 Created', ''); } $headers->add('HTTP/1.1 400 Bad request', ''); } else { throw new HttpException(403, Yii::t('yii', 'You are not authorized to perform this action.')); } if ($request->isAjax) { return $this->renderAjax('createFile_json', ['model' => $model]); } }