get folder path of a script?

Discussion in 'PHP' started by jasondavis, Feb 9, 2008.

  1. #1
    jasondavis, Feb 9, 2008 IP
  2. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Try:

    
    echo dirname(__FILE__);
    
    PHP:
    This should output the directory of the script that it resides in. (i.e. /test1/test2/)

    Jay
     
    jayshah, Feb 10, 2008 IP
  3. mab

    mab Active Member

    Messages:
    563
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    80
    #3
    try This ..

    
    echo $_SERVER['PHP_SELF'];
    
    PHP:
     
    mab, Feb 10, 2008 IP
  4. Cybernaut

    Cybernaut Peon

    Messages:
    408
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you access this script directly through browser:

    1. dirname($_SERVER['SCRIPT_NAME']) will give you /test1/test2
    2. prepend yourdomain name and append a slash to make it http://www.testing.com/test1/test2/

    If you access your script from within another script (php include) then:

    1. dirname(__FILE__) will give you full filesystem path to the directory containg script (like /home/domain/public_html/test1/test2)
    2. Strip DOCUMENT_ROOT ($_SERVER['DOCUMENT_ROOT']) from the beginning of the full path. It will leave you with /test1/test2
    3. prepend yourdomain name and append a slash to make it http://www.testing.com/test1/test2/

    Cybernaut.
     
    Cybernaut, Feb 10, 2008 IP