locating general file path

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jaymoore_299
Forum Contributor
Posts: 128
Joined: Wed May 11, 2005 6:40 pm
Contact:

locating general file path

Post 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.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

The $_SERVER variable will hold all the information you need :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

The other interesting is the include path setting...
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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.
Post Reply