1function getHtmlRootFolder(string $root = '/var/www/') {
2
3 // -- try to use DOCUMENT_ROOT first --
4 $ret = str_replace(' ', '', $_SERVER['DOCUMENT_ROOT']);
5 $ret = rtrim($ret, '/') . '/';
6
7 // -- if doesn't contain root path, find using this file's loc. path --
8 if (!preg_match("#".$root."#", $ret)) {
9 $root = rtrim($root, '/') . '/';
10 $root_arr = explode("/", $root);
11 $pwd_arr = explode("/", getcwd());
12 $ret = $root . $pwd_arr[count($root_arr) - 1];
13 }
14
15 return (preg_match("#".$root."#", $ret)) ? rtrim($ret, '/') . '/' : null;
16}
17