SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2006
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    getting back to the root

    Hi,

    I am having trouble with paths such as

    /includes/new.php

    however this works

    ../includes/new.php

    I am running PHP on IIS

    Any Ideas?


    Thanks

    Sinky

  2. #2
    SitePoint Enthusiast
    Join Date
    Jan 2006
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Starting a path off with a slash (/) means it's absolute, i.e. starting from root. Starting with ".." makes it relative, starting up one from the current directory. "includes/new.php" (without the slash in front) tells the script to start from the current directory and look in "includes".

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2006
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry I should have made my slef more clear.

    includes is at the root so i theory this should work from anywhere in the site

    /includes/new.php

    However it does not.

    If I am in say www.somesite.com/test/new.php

    I can get to www.somesite.com/includes/new.php

    By doing ../includes/new.php

    But not

    /includes/new.php

    Is this a php.ini thing

    Thanks

    Sinky

  4. #4
    SitePoint Enthusiast GhostGambler's Avatar
    Join Date
    Apr 2007
    Location
    Germany, NRW
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The directory "includes" is at the root of your ftp directory structure. This does not mean that it's actually the document root...

    PHP Code:
    echo $_SERVER['DOCUMENT_ROOT']; 
    If you run this in your ftp root directory you can take a look at where your ftp directory is actually located and then make a correct absolute path.
    (A common way to fix this problem is to just use a constant before includes: so something like
    PHP Code:
    include (BASE_DIR '/includes/new.php'); 
    you can define BASE_DIR with $_SERVER['DOCUMENT_ROOT'] or set it to another value if the value of the server var is incorrect because of lacking server config or whatever)

  5. #5
    SitePoint Evangelist pompopom's Avatar
    Join Date
    Feb 2004
    Location
    Huldenberg (Belgium)
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have more or less the same problem...

    when I'm in:

    HTML Code:
    http://admin.mydomain.be/index.php
    and need to get to:

    HTML Code:
    http://www.mydomain.be/includes/init.php
    I use
    PHP Code:
    ../includes/init.php 
    since the document root for the admin.mydomain.be is a subfolder named 'admin' in the document root for mydomain.be.
    This works fine!

    Now when I need to get to an image located in:

    HTML Code:
    http://www.mydomain.be/pics/open/image.jpg
    I use
    PHP Code:
    ../pics/open/image.jpg 
    but the only thing I get is the famous "red cross"....

    the picture IS actually there cause when I try to reach it straight with:

    HTML Code:
    http://www.mydomain.be/pics/open/image.jpg
    I do see the image...

    any ideas?

    thx!
    Koen
    The Path of excess leeds to the tower of wisdom (W. Blake)

  6. #6
    SitePoint Enthusiast GhostGambler's Avatar
    Join Date
    Apr 2007
    Location
    Germany, NRW
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://admin.mydomain.be/
    ../pics/open/image.jpg
    Where should this end?

    /www/admin/
    ../pics/open/image.jpg
    Where does this end?

    Difference between server and browser view on the directory structure seems to be unclear~

  7. #7
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem you're having, pompopom, is that you are confusing web paths and filesystem paths. Anything you send out to the browser (such as image paths) use web paths; anything you do server-side (such as PHP includes) use filesystem paths.

    If your image is at http://www.mydomain.be/pics/open/image.jpg, then an absolute path would be /pics/open/image.jpg (although if your page is on the admin.mydomain.be subdomain, then you must include the domain in the path as well).

    If your current script is in /home/pompopom/admin/index.php, and your include at /home/pompopom/includes/inc.php, then a relative path would be ../includes/inc.php and an absolute path would be /home/pompopom/includes/inc.php. Note that the /home/pompopom part is never seen by the browser yet is necessary for server-side absolute paths.
    PHP questions? RTFM
    MySQL questions? RTFM

  8. #8
    SitePoint Evangelist pompopom's Avatar
    Join Date
    Feb 2004
    Location
    Huldenberg (Belgium)
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    aha I see

    So you can't make a relative path to images if they aren't in the same domain even if the actual path on the server is only 'a folder' away

    thx, i didn't knew this

    greetz,
    Koen
    The Path of excess leeds to the tower of wisdom (W. Blake)


Bookmarks

Posting Permissions

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