Root directory path

Discussion in 'PHP' started by AHA7, Jan 16, 2007.

  1. #1
    Hello,

    How can I get the root directory path of my site to use it later in subdirectories. For example: my domain is "domain.com", I have an image in the directory "domain.com/dir/img.gif" and I want to link to that image from "domain.com/dir1/dir2/dir3/dir4/index.php" so is there any function that can return the path to the root directory "domain.com" so that I can later use something like: <? "function that returns the root path" ?>/dir/img.gif in the file index.php?

    How can I do that?
    P.S. I don't want to use full URL (http://...), I need a way to do it with relative paths.
     
    AHA7, Jan 16, 2007 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    
    <?
    $_SERVER['DOCUMENT_ROOT'];
    ?>
    
    PHP:
     
    krakjoe, Jan 16, 2007 IP
    AHA7 likes this.
  3. AHA7

    AHA7 Peon

    Messages:
    445
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Worked!
    Thanks a lot!
     
    AHA7, Jan 16, 2007 IP
  4. Nikolas

    Nikolas Well-Known Member

    Messages:
    1,022
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    150
    #4
    In some cases you can also use :

    dirname(__FILE__)
    PHP:
     
    Nikolas, Jan 16, 2007 IP