Possible Duplicate:
PHP: Why such weird behaviour when I include a file from another directory which also includes a file?
I have a problem including a file that has an included file.
-
core.inc.php PATH:
www/test/includes/core.inc.php -
included file in core.inc.php :
include_once ('../../connectdb.php'); -
connectdb.php PATH:
www/connectdb.php -
index.php PATH:
www/test/index.php -
included file in index.php :
include_once ('included/core.inc.php');
When I run index.php the following warnings are popping up:
(!) 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
In order to dinamically change the included paths what is the best practice? Please help me on my problem. Thank you.
To avoid such problems, you may use PHP magic constant
__DIR__which will be replaced by current file’s directory.For example:
Note that
__DIR__is only available for PHP 5.3+. Below that version you can replace__DIR__bydirname(__FILE__)BTW, autoloading is a good practice to avoid includes mess.