开发者

php file inclusion and it's manipulation

I am sure that sometimes it happens that you may need main file inclusion and when you write this code :

include(dirname(__FILE__) . "/../../core.php");

it will give you such a error :

Warning: include(../../../db/mysql.php) [function.include]: failed to open stream: No such file or directory in D:\Softwares\wamp\xampp\htdocs\***\db\db开发者_高级运维.php on line 38

its clear that in core.php there is another inclusion for db/mysql and when we include it from sub directories this problem happens

concider you are in a path like this : /includes/filemanger/

and you need to connect to your database and core.php needed !

so how to include core.php in root path ?


This is what set_include_path() is for.


Using $_SERVER['DOCUMENT_ROOT'] or creating constant

of root path can save you from this type of problems.

define('COREPATH',$_SERVER['DOCUMENT_ROOT']."/dir/core.php");

require_once(COREPATH);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜