I have a server where the public root is located at: /var/www/example.com/html/
.
Using $_SERVER['DOCUMENT_ROOT']);
I get the following result:
/var/www/example.com/html/
What $_SERVER
array key would I use to get the path directly above the public root? That is, the one here:
/var/www/example.com/
This will have to work on multiple environments, such as local and live. Not sure if there's some way of doing ./
document_root sort of thing.
dirname()
returns the parent directory of a directory and is platform independent.
dirname($_SERVER['DOCUMENT_ROOT']);
Should return:
/var/www/example.com
If you need the trailing slash then you can append DIRECTORY_SEPARATOR
:
dirname($_SERVER['DOCUMENT_ROOT']) . DIRECTORY_SEPARATOR;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With