PHP include() correct path but error anyway?

Discussion in 'PHP' started by vincent.fedorchak, Jun 29, 2010.

  1. #1
    Hello everyone! I know I must be doing something wrong, but I can't seem to figure out what it is!

    When I use:
    include '/dev/OnlineStores/lib/olsWebApp_Common.php';
    PHP:
    .. I get the following error message:

    However, I can literally take the path given in the error message ("/dev/OnlineStores/lib/olsWebApp_Common.php"), punch it into my address bar, and the page loads just fine.

    The php file that uses the include currently resides in /dev/OnlineStores/svc/poapprove/list.php. If I use a relative path (i.e., "../../lib/olsWebApp_Common.php") it works just fine, just not the full path. The crazy thing is that I've include()'d the exact same full path on other pages in the site without any problem!

    I'm admitting defeat and hoping somebody else sees what I'm missing. :)

    Thanks in advance!
     
    vincent.fedorchak, Jun 29, 2010 IP
  2. vincent.fedorchak

    vincent.fedorchak Guest

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Just in case this helps, here's the directory structure:

    ROOT
    -/dev
    --/OnlineStores
    ----/lib
    ----/css
    ----/imb
    ----/log
    ----/svc
    -------/poapprove
    -----------list.php <--- file that uses the include()
     
    vincent.fedorchak, Jun 29, 2010 IP
  3. mfscripts

    mfscripts Banned

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    8
    Trophy Points:
    90
    Digital Goods:
    3
    #3
    Is ROOT your site root or your server root? Try:

    include 'dev/OnlineStores/lib/olsWebApp_Common.php';

    (removing the / at the beginning)
     
    mfscripts, Jun 29, 2010 IP
  4. vincent.fedorchak

    vincent.fedorchak Guest

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The ROOT is the server root, which is why I'm confused.

    Actually, adding $_SERVER['DOCUMENT_ROOT'] in front of the include fixed the problem. The total code is:

    
    include $_SERVER['DOCUMENT_ROOT'] . '/dev/OnlineStores/lib/olsWebApp_Common.php';
    
    PHP:
    I can't say I totally understand why this works and the other way doesn't, but I'm happy either way.

    Thanks for your reply :)
     
    vincent.fedorchak, Jun 29, 2010 IP
  5. Zerix

    Zerix Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    PHP doesn't work like CSS and HTML, it doesn't go from current location or take "/" to mean go to root. That will be what was creating the problem :)
     
    Zerix, Jun 29, 2010 IP
  6. krsix

    krsix Peon

    Messages:
    435
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #6
    because php is looking for a FULL server side path, not just what's being served to the client.
     
    krsix, Jun 29, 2010 IP