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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Directory Path!!! Pls Help

Status
Not open for further replies.

Forri

Programmer
Joined
Oct 29, 2003
Messages
479
Location
MT
Hi all

I would like to know how i can get to the upper most in my directory!?

ie if my root directory is c:\mydir

and i'm in c:\mydir\tools\admin\library\tool.php

and want to get an include from c:\mydir\library\inc.php!

I know i can do ../../../ but thats ridiculous ...i think there is a more creative way to get there! i remember in my ASP days there was the Server.path!

Thanks
Nick
 
*nix :cd /
win* :cd


______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Thanks for your response: can you tell me exactly how to use them within my include function because i can't get it to work!

Tahnks
Nick
 
PHP's include(), include_once(), require(), and require_once() functions are not constrained to your web server's document root. And PHP can understand unix-style forward slashes for directory separators, even on Win32.

The "gotcha" is to be careful of backslashes inside doublequotes.

include ('c:\mydir\library\inc.php');

or

include ("c:/mydir/library/inc.php");

should do it.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Also of note are $_SERVER[DOCUMENT_ROOT], however this does not appear to behave correctly under IIS

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Sleipnir 214 your right but if i want to change server i have to change the settings .... even though few are present! If there is an easier way to get to the top root of my current folder it would be nice!

Tahnks

 
If you move to a new server and your directory structure changes, there is not much you can do programmatically to account for it.

If you want to have to make the minimum necessary changes to your code should you move, create a configuration file that puts the directory name in a constant or variable. Then every script in your app includes that local file and includes other files based on that constant's value.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top