include problem

Discussion in 'PHP' started by jessecooper, Nov 26, 2007.

  1. #1
    so i playing around with php and im having a problem...

    Im trying to access the folder 'includes' from my main directory using
    include ('/includes/header.php');
    PHP:
    which returns the error
    Warning: include(/includes/header.php) [function.include]: failed to open stream: No such file or directory in /home/cp/public_html/j7/bt/index.php on line 3
    
    Warning: include() [function.include]: Failed opening '/includes/header.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/j7/public_html/cp/bt/index.php on line 3
    Code (markup):
    now when i access the 'includes' files from another folder, like so
    include ('../includes/header.php');
    PHP:
    it works just fine and things are happy

    can anyone tell me what the problem could be?
    Is there a fix for accessesing lower level folders with includes?
    i've also tried removing the "/" to make
    include ('includes/header.php');
    PHP:
    that returns no error but doesn't render correctly
     
    jessecooper, Nov 26, 2007 IP
  2. *louie*

    *louie* Peon

    Messages:
    48
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you could try the full path:
    
    include ("/home/cp/public_html/j7/bt/includes/header.php");
    
    PHP:
     
    *louie*, Nov 26, 2007 IP
    jessecooper likes this.
  3. kentuckyslone

    kentuckyslone Notable Member

    Messages:
    4,371
    Likes Received:
    367
    Best Answers:
    0
    Trophy Points:
    205
    #3
    *louie* is correct. When you try to pull up the include file as you did in a subfolder 'it' will expect the includes directory to be within that subfolder
     
    kentuckyslone, Nov 26, 2007 IP
    jessecooper likes this.
  4. -NB-

    -NB- Peon

    Messages:
    153
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Try this out.
    
    set_include_path('includes');
    include 'header.php';
    
    PHP:
    Should work from any subdirectory :)
     
    -NB-, Nov 26, 2007 IP
    jessecooper and kentuckyslone like this.
  5. kentuckyslone

    kentuckyslone Notable Member

    Messages:
    4,371
    Likes Received:
    367
    Best Answers:
    0
    Trophy Points:
    205
    #5
    I tried this on one of my pages and it works fine for me.
     
    kentuckyslone, Nov 26, 2007 IP
  6. jessecooper

    jessecooper Peon

    Messages:
    793
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    0
    #6
    thanks guys, fixed

    mods please close
     
    jessecooper, Nov 26, 2007 IP