PHP absolute path to root

后端 未结 7 1895
轻奢々
轻奢々 2020-11-28 05:44

I can\'t believe PHP doesn\'t have an easy solution for this simple matter. ASP.NET has a ~ sign that takes care of this issue and starts everything from the root level. Her

7条回答
  •  旧巷少年郎
    2020-11-28 06:35

    The best way to do this given your setup is to define a constant describing the root path of your site. You can create a file config.php at the root of your application:

    
    

    Then include config.php in each entry point script and reference SITE_ROOT in your code rather than giving a relative path.

提交回复
热议问题