inclusive includes problem

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
sportsdude11751
Forum Newbie
Posts: 4
Joined: Sun Jul 15, 2007 11:39 am

inclusive includes problem

Post by sportsdude11751 »

I'm having a few problems with some include() statements in my php. I have to include some scripts that are in a seperate file, so I use the ".." to go back a directory (to my main directory) so something like this include("../standAlones/openHalf.php"); However, that script (openHalf.php) includes something from another file, and thats where i get my errors. I tried using set_include_path, but i'm not to sure on how it works. If you have any ideas on how to approach this different, or know of a fix, or have an example of set_include_path, i would greatly appreciate it! -Thanks
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

relative paths like ../standAlones/openHalf.php are always relative to the current working directory (cwd).
Php sets the cwd to the path of the "main" script. An include() or require() doesn't change the cwd. In case of doubt print the cwd via echo 'cwd: ', getcwd();
If you want the current script file's location as "anchor" use e.g. __FILE__ and dirname()
sportsdude11751
Forum Newbie
Posts: 4
Joined: Sun Jul 15, 2007 11:39 am

Post by sportsdude11751 »

is there a way to set the cwd to a different location?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Yes, chdir().
Are you sure you want to use it instead of providing the "proper" path?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

set_include_path() is fairly explanatory. If you look at Example 1829 on the linked page, it gives a more complex use.
Post Reply