Forum Moderators: coopster

Message Too Old, No Replies

"include path" doesn't function the way I thought it would

         

androidtech

1:42 am on Jun 16, 2007 (gmt 0)

10+ Year Member



I have a PHP script that resides in a public directory. The real directory is something like this (directory names changed but nesting level holds true):

/usr/top/public/the-script.php

This is the path that is shown if I print __FILE__. I have an include directory that lives here:

/usr/top/hidden

I do the following with ini_set:

ini_set("include_path", ".;/usr/top/hidden");

However if I try to include a file that resides in /usr/top/hidden using just the file name:

require_once("file-in-hidden-dir.php");

I get a fatal error saying the file could not be found, with the include path I set showing in the error dump as the correct include_path.

If I try opening up the file using an explicit full path declaration:

require_once("/usr/top/hidden/file-in-hidden-dir.php");

It opens without error. What could I be doing wrong to have this problem?

Thanks.

eelixduppy

1:26 pm on Jun 16, 2007 (gmt 0)



Try this:

ini_set("include_path", ".:/usr/top/hidden");

You use a colon to separate the directories on a unix machine. You only use a semicolon for windows. See if changing that fixes anything.

androidtech

7:30 pm on Jun 16, 2007 (gmt 0)

10+ Year Member



Thanks you. That worked like a charm. You know, I even looked at one of the ini_set("include_once", _) examples and did notice a colon, but I figured the example was wrong! Perception is a tricky thing.

coopster

12:01 pm on Jun 18, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yeah, sometimes you have to look at the directives themselves to get more information. I find that the functions which are impacted by directive settings require some further reading into the directive itself and it really helps to keep this thought in mind for future reference. In this case, you would have followed the link to the include_path [php.net] directive.