Is there a $_SERVER['DOCUMENT_ROOT'] equivalent which would work on both Apache and IIS without having to change configuration files? Or maybe some workarounds?
1 Answer
For IIS
if(empty($_SERVER['DOCUMENT_ROOT']) && !empty($_SERVER['SCRIPT_FILENAME'])) {
$_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0 - strlen($_SERVER['PHP_SELF'])));
}
if(empty($_SERVER['DOCUMENT_ROOT']) && !empty($_SERVER['PATH_TRANSLATED'])) {
$_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/', substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0 - strlen($_SERVER['PHP_SELF'])));
}
getcwd();(PHP4/PHP5) and some logic to get what you need?getcwdfailed. You should be more focused on creating a viable solution instead of catering to exceptions that you'll likely never encounter.