Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question