可能重复已经包含在PHP文件的文件:
PHP: Why such weird behaviour when I include a file from another directory which also includes a file?包括[警告(!)
我有一个问题,包括有一个包含文件的文件。
core.inc.php PATH:
www/test/includes/core.inc.php
列入core.inc.php文件:
include_once ('../../connectdb.php');
connectdb.php PATH:
www/connectdb.php
的index.php PATH :
www/test/index.php
在在index.php中cluded文件:
include_once ('included/core.inc.php');
当我运行的index.php以下警告弹出:
(!) Warning: include_once(../../connectdb.php): failed to open stream: No such file or directory in G:\wamp\www\test\includes\core.inc.php on line 7
(!) Warning: include_once(): Failed opening '../../connectdb.php' for inclusion (include_path='.;C:\php\pear') in G:\wamp\www\test\includes\core.inc.php on line 7
为了dinamically更改所包含路径最佳做法是什么?请帮我解决我的问题。谢谢。
用当前文件的目录开始相对路径,即'require_once dirname(__ FILE__)。 '/relative/path/to.file.php';' – DCoder
提供相对于您正在编辑的文件的路径。 – Deadlock
这是一个明确定义的问题,使用'__FILE__'和/或'__DIR__ '得到你的文件的路径,而不是'include_path'。有很多问题,例如,这个问题的答案似乎相当不错,但问题本身有点长。刚刚阅读接受的答案:http://stackoverflow.com/questions/3099357/php-why-such-weird-behaviour-when-i-include-a-file-from-another-directory-which?rq=1 – Nanne