How to get root directory in yii2

后端 未结 7 1873
闹比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:54

    Supposing you have a writable "uploads" folder in your application:

    You can define a param like this:

    Yii::$app->params['uploadPath'] = realpath(Yii::$app->basePath) . '/uploads/';
    

    Then you can simply use the parameter as:

    $path1 = Yii::$app->params['uploadPath'] . $filename;
    

    Just depending on if you are using advanced or simple template the base path will be (following the link provided by phazei):

    Simple @app: Your application root directory

    Advanced @app: Your application root directory (either frontend or backend or console depending on where you access it from)

    This way the application will be more portable than using realpath(dirname(__FILE__).'/../../'));

    0 讨论(0)
提交回复
热议问题