Reputation: 92
I am using include or include_once in php core project
include('test1/footer.php');
this is working in root folder ..
but we using above code in anyfolder like name test2 and include test1 file in test2 here above code not working..include('test1/footer.php');
please help me .
thanks..
Upvotes: 0
Views: 2824
Reputation: 1
best practice for me is to define a constant containing server ROOT path (or other path that is base for your includes)
add code to
root/index.php
or to a configuration file if you have one
define('MYROOT', dirname(__FILE__));
use it anywhere in the project code, its also good when you change files hierarchy:
include(MYROOT.'test1/footer.php');
Upvotes: 0
Reputation: 86
check this screen shot to understand structure
if you want to add "configs.php" in "cargo.php" write this include('include/configs.php'); and if you want to add "cargo.php" in "configs.php" write this include('../cargo.php');
better use include_once(); not only include();
Upvotes: 0
Reputation: 9103
folder structure
/root
/test1
footer.php
index.php
index.php
//works fine because test1 is on the same level as index.php
include('test1/footer.php');
folder structure
/root
/test1
footer.php
/test2
index.php
index.php
//does not work since in our current folder there is no folder "test1"
include('test1/footer.php');
//does work since we go back to root first
include('../test1/footer.php');
Upvotes: 1
Reputation: 986
Try this,
include('../test1/footer.php');
But both test1 and test2 on same level.
Upvotes: 0