문제

There's a little library I'm trying to plug in to my project. This lib has some includes and requires across classes, so I'm trying to set an include path for all that to work.

When trying to set an include path off a sibling branch, I run into a hiccup.

For a reference point, require('/../my/test.php') works fine.

So does

set_include_path('/../');
require_once('my/test.php');

But once I try

set_include_path('/../my/');
require_once('test.php');

I get:

Warning: require_once(one.php): failed to open stream: No such file or directory in ...

What am I missing?

도움이 되었습니까?

해결책

Starting your paths with / means look in the root directory, so /../ is technically one directory above the root directory.

To set the include path to the parent directory of the current location, you just need ../. To make the code more portable I would suggest combining it with dirname(__FILE__) to get the absolute path of the current directory.

IE:

set_include_path(dirname(__FILE__) . '/../my/');

Note the preceding / is required in that example as dirname() does not return a trailing slash

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top