save picture from backend to frontend

Hi I have function:


 public function upload()

    {

        

        if ($this->validate()) {

            $this->File->saveAs('uploads/banners/' . $this->Url . '.' . $this->File->extension);

            $this->Image='uploads/banners/' . $this->Url  . '.' . $this->File->extension;

           

            return true;

        } else {

            return false;

        }

    }

I use it in controller in backend, so it save this picture in backend/webuploads/banners/. What can I do to using this function in backend but save this picture in fronten/web/uploads/baners

Hi,

Does it not work with the path alias?

@frontend/web/uploads/banners/

Take a look at:

http://www.yiiframework.com/wiki/667/yii-2-list-of-path-aliases-available-with-default-basic-and-advanced-app/

Best Regards

saveAs function uses path of the filename to be saved. If your backend and frontend are in same server, you can give the path to the frontend directory you want your file to be saved, that you must be knowing.

when i used this path:


public function upload() {


        if ($this->validate()) {

            $this->File->saveAs('@frontend/web/uploads/banners/' . $this->Url . '.' . $this->File->extension);

            $this->Image = '@frontend/web/uploads/banners/' . $this->Url . '.' . $this->File->extension;


            return true;

        } else {

            return false;

        }

    }

I have error:

but in fronted i created this directory uploads/banners