开发者

PHP: include file relative to calling file NOT root file?

OK say I have a file called fileA.php in the same directory I have another file called fileB.php

so inside fileA there is this require_once('fileB.php') notice I did not specify a file path because both files are in the same directory.

Now if fileA is included into another file that is located somewhere else, it fails to include fileB because the parent file (the file that included fileA) is not in the same directory as fileB.

So how can I make 开发者_如何转开发it so that fileA loads fileB no matter where fileA is included into?

Does that make sense?

Thanks!!


Assuming both fileA.php and fileB.php are guaranteed to be in the same directory, this should work:

// fileA.php
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR .'fileB.php')


http://php.net/manual/en/function.include.php#78716

You can set the include root to your website root.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜