Mac Taylor
Mac Taylor

Reputation: 5168

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 ?

Upvotes: 1

Views: 124

Answers (2)

Jeff Hubbard
Jeff Hubbard

Reputation: 9902

This is what set_include_path() is for.

Upvotes: 3

Shakti Singh
Shakti Singh

Reputation: 86406

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);

Upvotes: 0

Related Questions