A
A
Ainur1232018-04-19 19:44:48
Yii
Ainur123, 2018-04-19 19:44:48

How to upload files in Yii2?

I'm trying to upload a file in Yii2, but it doesn't work. I did it according to the principle of loading an image

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

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-04-19
@webinar

Well, your path is clearly not complete. You need to specify the full path. For example:
and I don't quite understand why you delete it immediately? And if so, what are you expecting?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question