Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function actionCreate()
- {
- if (!Yii::$app->user->isGuest) {
- $model = new Product();
- if ($model->load(Yii::$app->request->post())) {
- $documentName=$model->id;
- $model->file=UploadedFile::getInstance($model,'file');
- $model->file->saveAs( 'uploads/'.$documentName.'.'.$model->file->extension);
- $model->document='uploads/'.$documentName.'.'.$model->file->extension;
- $model->save();
- return $this->redirect(['index']);
- } else {
- return $this->render('create', [
- 'model' => $model,
- ]);
- }
- } else {
- $this->redirect('/site/index');
- }
- }
- <p><a href="<?= $product->document?>" download>Скачать файл</a>
- public function actionCreate()
- {
- if (!Yii::$app->user->isGuest) {
- $model = new Product();
- if ($model->load(Yii::$app->request->post())) {
- $model->file=UploadedFile::getInstance($model,'file');
- $model->file->saveAs( 'uploads/'.$model->file->baseName.'.'.$model->file->extension);
- $model->document='uploads/'.$model->file->baseName.'.'.$model->file->extension;
- $model->save();
- return $this->redirect(['index']);
- } else {
- return $this->render('create', [
- 'model' => $model,
- ]);
- }
- } else {
- $this->redirect('/site/index');
- }
- }
Add Comment
Please, Sign In to add comment