I try to upload files in backend and each time i uploaded a file it was successfully uploaded and successfully saved in the DB but it wasn\'t save to the directory i specified s
$path = '/uploads/';
That means you are uploading files to /uploads
, the top level folder in the system.
Run cd /uploads
in your terminal and check, most likely files were uploaded there.
To fix that, you need to specify correct full path. The recommended way to do it is using aliases.
In case of advanced application, you already have @backend
alias, so you can use it:
$this->img->saveAs(\Yii::getAlias("@backend/web/uploads/{$randomString}.{$this->img->extension}");
Or create your own alias in common/config/bootstrap.php
:
Yii::setAlias('uploads', dirname(dirname(__DIR__)) . '/backend/web/uploads');
And then use it like this:
Yii::getAlias('@uploads');
Don't forget to include use Yii
if you are not in root namespace or use \Yii
;
If you want your images to be accessible on frontend, you can create symlink between frontend and backend images folders.