Page 1 of 1

Add script's parent directory to include_path

Posted: Fri Oct 06, 2006 12:02 am
by rmccue
One more PHP question:
How do I add the parent directory ( ../ ) to the include path?
I have tried using

Code: Select all

ini_set('include_path',ini_get('include_path').';..;');
set_include_path('..' . PATH_SEPARATOR . get_include_path() );
but in the file in the parent directory it uses

Code: Select all

require_once './conf.php';
and the script fails on this.
Thanks

Posted: Sun Oct 08, 2006 5:12 am
by rmccue
Weirdan wrote: You may bump it since it's about 2 days old.
In that case, Bump :D

Posted: Sun Oct 08, 2006 12:13 pm
by Ambush Commander
In general, using relative paths in the include path is not a good idea. You probably would be better off hard-coding the path. The double-dot notation should work, but since it doesn't seem to in your case, you can try:

Code: Select all

set_include_path(realpath('..') . PATH_SEPARATOR . get_include_path() );

Posted: Mon Oct 09, 2006 2:24 am
by rmccue
I am trying to avoid hard-coding paths, because it's just one more thing that can go wrong ;)
That doesn't work either :(
Should I try getting rid of the . in the include paths?

Posted: Mon Oct 09, 2006 9:32 am
by Ambush Commander
I think I might need more information. Can you give me your directory structure? Where is conf.php located?

Posted: Wed Oct 11, 2006 1:48 am
by rmccue
The directory structure is like this:

/conf.php
/lib.php
/admin/
/admin/index.php
/inc/magpie/rss_parse.php

I am including lib.php from admin/index.php, which includes ./conf.php
lib.php also includes ./inc/magpie/rss_parse.php (in case having more in other directories matters)

Posted: Wed Oct 11, 2006 2:29 am
by RobertGonzalez
In your file that is below root (admin/whatever.php) add this line to the beginning of the file...

Code: Select all

<?php
$path_to_root= './../';
?>
Then, whatever you want to include in that script that is in the root folder can be called like:

Code: Select all

<?php
include $path_to_root . 'filename.php';
?>
Of course, you could always build a realpath and use that throughout your script so it makes no difference what your files are. Or, you can process includes once in one spot, and not worry about them throughout the script.

Posted: Wed Oct 11, 2006 2:50 am
by rmccue
That's what I have resorted to for now.
However, if there are any other options, that would probably be easier.