How to get the absolute path to the public_html folder?

后端 未结 11 1360
离开以前
离开以前 2020-12-08 14:25
$_SERVER[\'DOCUMENT_ROOT\']

returns

/usr/local/apache/htdocs/

is there a way to get

/home/us         


        
11条回答
  •  Happy的楠姐
    2020-12-08 15:10

    You just need to create an offset bypass to how far you want the backwards reading to go. So, we use getcwd() to get the path and explode (split into array) to fetch the data between $root and the ending of the path.

    function getRoot($root = "public_html") {
        return explode($root, getcwd())[0].$root."/";
    }
    

提交回复
热议问题