How to programmatically determine the document root in PHP?

后端 未结 6 1835
猫巷女王i
猫巷女王i 2020-12-15 13:28

Here\'s a problem that I\'ve been running into lately - a misconfigured apache on a webhost. This means that all scripts that rely on $_SERVER[\'DOCUMENT_ROOT\']

6条回答
  •  长情又很酷
    2020-12-15 14:10

    In PHP5 there is the magic constant __FILE__ that contains the absolute path of the file in which it appears. You can use it in combination with dirname to calculate the document root.

    You can put a statement like the following one in a config file

    define ('DOCUMENT_ROOT', dirname(__FILE__));
    

    this should do the trick

提交回复
热议问题