Page 1 of 1

inclusive includes problem

Posted: Sun Jul 15, 2007 11:41 pm
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

Posted: Mon Jul 16, 2007 3:18 am
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()

Posted: Mon Jul 16, 2007 10:31 am
by sportsdude11751
is there a way to set the cwd to a different location?

Posted: Mon Jul 16, 2007 2:09 pm
by volka
Yes, chdir().
Are you sure you want to use it instead of providing the "proper" path?

Posted: Mon Jul 16, 2007 10:47 pm
by feyd
set_include_path() is fairly explanatory. If you look at Example 1829 on the linked page, it gives a more complex use.