Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
02-22-2012, 05:27 PM #1
- Join Date
- Feb 2012
- Thanked 0 Times in 0 Posts
Php Include Files for Subdirectory
I'm building a simple php website with include files(using XAMPP right now) and I can't seem to find the correct path for the includes in my subdirectory files. I've tried adding the double period slash but didn't work.
Basically the site is in the htdocs folder like this(' ' are the folders):
I need to get the header, leftnavigation and footer includes in the
dda.php file which is in the 'dd' file but i don't want to create another includes file. Help.
02-22-2012, 06:06 PM #2
- Join Date
- Sep 2002
- Saskatoon, Saskatchewan
- Thanked 2,662 Times in 2,631 Posts
Sounds to me like the problem you will likely be trapped in is the pwd of the executing directory. Using a relative include no matter what script its defined in will always work relative to the pwd of the executing script. So with this, dd is located under /dd, which included /dd/dda.php, which in turn includes /includes/*.
Since you mentioned .., this would indicate relative. Use this for your inclusion within dda.php:
require_once dirname(__FILE__) . '/../includes/header.include.php';
Now when you include dda.php into dd.php, whether you pull from the dirname or not the inclusion within the dda.php will resolve relative from /dd, and not from /.