How can I find my htdocs directory.
When I execute the following command:
echo dirname(__FILE__);
I get the following output:
/var/www/myexample.com/htdocs/required/css
I want to find path till /htdocs, but I don't want to hard-code the things
I know I can use:
dirname(dirname(dirname(__FILE__)))
But, that will work if the current file is in "css" directory. If I will move to some other directory inside "css" directory, then it will not work.
Any solution for this?
If you are running Apache, the
$_SERVER["DOCUMENT_ROOT"]
environment variable should give you the current document root. See $_SERVER in the manual.
On most setups $_SERVER['DOCUMENT_ROOT']
should give you what you want.
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