• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

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
0
mhoggatt1
Asked:
mhoggatt1
6 Solutions
 
keteracelCommented:
it can go back as many levels as there are in the filesystem
0
 
keteracelCommented:
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
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
keteracelCommented:
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
 
mensuckCommented:
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
 
PromethylCommented:
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
 
gruntarCommented:
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
 
herkules85Commented:
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now