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

后端 未结 6 785
眼角桃花
眼角桃花 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 10:00

    For the web root, there is DOCUMENT_ROOT as pointed out in several answers. For the application root, there is no way for the system to tell which folder in your application is the root folder. You will have to set that manually.

    Most applications define an application root using dirname(__FILE__); or a config setting and store that in a constant that is available throughout the application.

提交回复
热议问题