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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Karambunai Nexus
    Posts
    100
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need abit help with 'Includes' or some alternatives.

    If this has been asked before, please delete or move it.

    Let's say I made dir001 (within doc root) and place a file 001.php. Now inside dir001, i make a new dir, dir002 with a file 002.php inside it. Now inside file 002.php, is it possible to 'include' file 001.php which is outside its dir? If 'include' doesn't work, has anyone got any suggestions which i can play use or play around?
    nisi dominus fustra

    www.oopsmural.com

  • #2
    New Coder
    Join Date
    Dec 2005
    Posts
    35
    Thanks
    1
    Thanked 1 Time in 1 Post
    PHP Code:
    include ('../dir001/001.php'); 
    Should work. But I'm not 100% sure. If not you can use full directories such as:

    PHP Code:
    include ('http://www.yoursite.com/dir001/001.php'); 

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Quote Originally Posted by InsaneRhino View Post
    If not you can use full directories such as:

    PHP Code:
    include ('http://www.yoursite.com/dir001/001.php'); 
    Using the URL will only work if the server has allow_url_fopen is on. You should use the full file path if the relative one doesn't work. ie. /home/username/public_html/dir001/001.php This path will vary depending on the server, but you can find it in the phpinfo().

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Or most of the time this works as well...
    PHP Code:
    include($_SERVER['DOCUMENT_ROOT'].'/dir001/001.php'); 
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Karambunai Nexus
    Posts
    100
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, it works.
    nisi dominus fustra

    www.oopsmural.com

  • #6
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Quote Originally Posted by InsaneRhino View Post
    PHP Code:
    include ('../dir001/001.php'); 
    Should work. But I'm not 100% sure.
    This technique will work, and is the recommended way. Although if dir002 is contained within dir001, the path should be: ../001.php


  •  

    Posting Permissions

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