M
M
Max DangerPro2016-11-28 05:30:54
Yii
Max DangerPro, 2016-11-28 05:30:54

Are files not being uploaded to the server at the same time?

I've been sitting all night, ready not to cook, help! Help me)
Here is such a controller:

public function actionUpdate($id) {
        $model = $this->findModel($id);
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            $model->image = UploadedFile::getInstance($model,'image');
            if( $model->image ) {
                $model->upload();
            }
            $mfile = UploadedFile::getInstance($model, 'file');
            $model->bookfile = $mfile->name;
            $ext = end((explode(".", $mfile->name)));
            $model->bookfile = Yii::$app->security->generateRandomString().".{$ext}";
            $path2 = Yii::getAlias('@webroot').'/upload/global/books/'.$model->bookfile;
            if($model->save()) {
                $mfile->saveAs($path2);
                return $this->redirect(['view', 'id' => $model->id]);
            } else {
                return false;
            }
            return $this->redirect(['view', 'id' => $model->id]);
        }
        else {
            return $this->render('update', compact('model'));
        }
    }

It's in the model:
public function rules() {
        return [
            [['image'],'file','extensions' => 'png, jpg'],
            [['file'],'file','extensions' => 'txt,doc,pdf'],
        ];
    }

public function upload() {
        if($this->validate()) {
            $path = 'upload/store/'.$this->image->baseName.'.'.$this->image->extension;
            $this->image->saveAs($path);
            $this->attachImage($path, true);
            @unlink($path);
            return true;
        }
        else { return false; }
    }

Question: I open the information update page, in my case these are books, I add all the information and a picture. Everything is saved and loaded normally. The same situation is with the file (these are text files such as txt, pdf ...). But when I select both downloads at once, and not separately. I get this error:
finfo_file(D:\OpenServer\userdata\temp\phpCD25.tmp): failed to open stream: No such file or directory

Tell me what and where to add to me, how to fix it? Thank you in advance))

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question