...

View Full Version : Php Include Files for Subdirectory



username85
02-22-2012, 06:27 PM
Hello,

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):
'template14'

'css'

'dd'
dda.php

'images'

'includes'
header.include.php
leftnavigation.include.php
footer.include.php

dd.php

index.php

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.

Fou-Lu
02-22-2012, 07:06 PM
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';

etc. You can use whatever inclusion type you want.

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 /.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum