Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-22-2012, 05:27 PM   PM User | #1
username85
New Coder

 
Join Date: Feb 2012
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
username85 is an unknown quantity at this point
Php Include Files for Subdirectory

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.
username85 is offline   Reply With Quote
Old 02-22-2012, 06:06 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,647
Thanks: 4
Thanked 2,450 Times in 2,419 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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:
PHP Code:
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 /.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:40 PM.


Advertisement
Log in to turn off these ads.