Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find htdocs path, no matter where file is stored

Tags:

php

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?

like image 399
I-M-JM Avatar asked Sep 01 '25 10:09

I-M-JM


2 Answers

If you are running Apache, the

$_SERVER["DOCUMENT_ROOT"]

environment variable should give you the current document root. See $_SERVER in the manual.

like image 191
Pekka Avatar answered Sep 03 '25 00:09

Pekka


On most setups $_SERVER['DOCUMENT_ROOT'] should give you what you want.

like image 36
tobyodavies Avatar answered Sep 02 '25 23:09

tobyodavies