E
E
Elizabeth2017-06-23 15:49:43
Yii
Elizabeth, 2017-06-23 15:49:43

YII2 "failed to open stream: No such file or directory" How to fix?

My class for working with images:
51fe84e9158f4c83b7a1d2fcf08eed24.png
And its use:
58227858a3914ebda6b492cd831c2746.png
After that everything is fine
08c84250019548039f0f0d335cf3fa7b.png
But as soon as I write to save the image in a certain directory
6b57833ac5354b6586d9239d93f56599.png
, the following error pops up
071a23ef03a742f8b92ea579718fca73.png
even if I change and put a slash before uploads

$file->saveAs(Yii::getAlias('@web').'/uploads/'.$file->name);

Nothing will change. I am using MAMP server and macOS. Maybe that's why he can't find it? If yes, how to fix it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew, 2017-06-23
@elizaveta_kotik

@webroot points to the root of the application, you need to use it:

$file->saveAs(Yii::getAlias('@webroot').'/uploads/'.$file->name);

D
davidnum95, 2017-06-23
@davidnum95

Is the image saved?
Try this:
alias
preservation
Also check the write permissions to the directory.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question