How to get root directory in yii2

后端 未结 7 1889
闹比i
闹比i 2020-12-15 03:20

yii2 Question

My yii2 install in d:\\wamp\\www\\yii2store

I want to get above path to save images which will be uploaded by me

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-15 03:40

    To get the base URL you can use this (would return "http:// localhost/yiistore2/upload")

    Yii::app()->baseUrl
    

    The following Code would return just "localhost/yiistore2/upload" without http[s]://

    Yii::app()->getBaseUrl(true)
    

    Or you could get the webroot path (would return "d:\wamp\www\yii2store")

    Yii::getPathOfAlias('webroot')
    

提交回复
热议问题