How can I get the “application root” of my URL from PHP?

后端 未结 6 788
眼角桃花
眼角桃花 2020-12-09 09:06

If my URL is http://www.server.com/myapp/stuff/to/see and my directory structure on disk is htdocs/myapp/*, how can I extract the /myapp

6条回答
  •  粉色の甜心
    2020-12-09 09:58

    Try this:

     echo dirname(__FILE__);
    

    where __FILE__ is the name of current executing script, and dirname gets folder/application folder out of it.

    More Options:

    echo $_SERVER['DOCUMENT_ROOT']; // gives you the root dir
    

    On PHP.net

提交回复
热议问题