Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding The Server's Document Root

Status
Not open for further replies.

Itshim

Programmer
Apr 6, 2004
277
US
I have a directory where I store files of sensitive data (db credentials, and such) along with other files where I have altered the permissions, so that PHP can write to the files. Because of the nature of these files I place this directory outside the server's DOCUMENT ROOT

I am trying to figure out how I can dynamically locate the directory above the server's DOCUMENT ROOT. Normally I retrieve the $_SERVER['DOCUMENT_ROOT'] value from PHP, drop off the last directory in the path and I'm there.

The problem I am now having is with sub-domains, which (in the file system realm) is just a directory some where in server's DOCUEMNT ROOT, but the problem is that the DOCUMENT ROOT for a sub-domain is not the server's DOCUMENT ROOT, so the above method does not work.

Through PHP I can access the files in the directory without problems, but I have hard-coded the path in the scripts, and I wanted to find a way to dynamically locate the server's DOCUMENT ROOT.

Thanks.
 
would something like this help?
Code:
$abspathtocwd =  dirname( __FILE__ );
include = $abspathtocwd.'/../../somefile.php';
 
I see what you are getting at, but I hoping to find a way to get the value of $_SERVER['DOCUMENT_ROOT'] (when not reading from a sub-domain); even if I am parsing a file in a sub-domain.

I thought PHP may store the value of the server's document root (not the domain's doc root) some where.

I have come up with a hack that works, but just wanted to make sure I'm not missing a valid way of getting the value.

Thanks
 
The DocumentRoot is defined by the web server, and that's all PHP gets to work with. It sounds like you want to discover a specific one of potentially many DocumentRoots, which PHP won't be able to see.

In this case I'd probably place a global config file somewhere and source it in the PHP scripts. It would define something like $PrivateDir="/var/
 
lgarner, I think that would be the best solution, and is what I have decided to go with.

Thank you both...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top