Page 1 of 1

locating general file path

Posted: Thu Jan 05, 2006 1:06 pm
by jaymoore_299
When I want to refer to a file in the main directory I have to use something like this:
$a1=function_name("/usr/www/virtual/username/www.domain.com/file.txt",9);

Since the file is in my main folder for the domain, is there a more general way to refer to the file without writing out all the "/usr/www/virtual/username/" part?

Something like this
$a1=function_name("$_Find_main_domain_path()file.txt",9);

and it would always refer to that particular file in the main directory regardless what domain it is in.

Posted: Thu Jan 05, 2006 1:15 pm
by hawleyjr
The $_SERVER variable will hold all the information you need :)

Posted: Thu Jan 05, 2006 1:18 pm
by feyd
unless your php is set up in an odd fashion, you can do relative path references: ../somefile.txt would refer to the parent directory's (from current working directory) file

getcwd() may be of interest.

Posted: Thu Jan 05, 2006 5:13 pm
by timvw
The other interesting is the include path setting...

Posted: Fri Jan 06, 2006 5:53 am
by Jenk
if you are wanting the document root: $_SERVER['DOCUMENT_ROOT']

But as proven in a different thread, $_SERVER can be tainted (well, at least some of it) so for the ultra security tight developers, a better method may need to be sought.