Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2012
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 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:
    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 /.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •