PHP directory instructuins

In this type of instruction how many levels back or forwards can it go ? Please give some other examples.

require_once("../config.php");

Thanks,
Michael
mhoggatt1Asked:
Who is Participating?
 
gruntarConnect With a Mentor Commented:
I would advice you nto to "hard code" your paths. Use environmental variables instead like this...

require_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");

so that you don't have problem if you move file to annother dir or maybe on a different server..

cheers
0
 
keteracelCommented:
it can go back as many levels as there are in the filesystem
0
 
keteracelConnect With a Mentor Commented:
e.g. if current working directory is something like this:

c:\temp\folder\anotherfolder\yetanotherfolder\howmanyfolderscanIbebotheredtotype\lastfolder\

then if c:\temp contained the file of interest...

require_once("../../../../../config.php");

this would work...
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
mhoggatt1Author Commented:
Can I specify a foler in a sublolder such as -
C:\temp\config\ this_folder

In other words can I go forwrd as well as backwards ?
0
 
keteracelConnect With a Mentor Commented:
yeah...

require_once("../../../../../../temp/config.php"); // if you are in the dir shown above...

would work as would:

require_once("temp/config.php"); //if you are in c:/
0
 
mensuckConnect With a Mentor Commented:
But you do know that everytime the script is run PHP will have to go looking for the directory that contains 'config.php'. The directory or path is not cached! You are better off using PHP directory type functions: ( http://us2.php.net/manual/en/ref.dir.php )than doing silly stuff like that!


Suzanne
0
 
PromethylConnect With a Mentor Commented:
You can go any direction, but at the level you're at, you may consider an absolute path ...

Require_once("C:\\temp\\config.php");

Something like that. Keep in mind temp could be accessed by all users, so securitywise this may be a bad practice.
0
 
herkules85Connect With a Mentor Commented:
require_once("/file.php"); //this file is in c:/file.php if you are using windows or root dir if unix
0
 
mhoggatt1Author Commented:
Thanks everyone for all your expertise. It really has helped a lot.
Michael
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.