detecting directory

Discussion in 'PHP' started by promotingspace.net, Dec 29, 2008.

  1. #1
    Hi
    I need a command that returns the directory name that my file is in
    for example if my file is www/javad/codes/getdir.php , then I want to place a code in getdir.php that returns "codes" (and if possible "javad")
    Thanks for your help
     
    promotingspace.net, Dec 29, 2008 IP
  2. tamen

    tamen Peon

    Messages:
    182
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $_SERVER is your friend.
    Do a print_r($_SERVER); to see which part suits you.
     
    tamen, Dec 29, 2008 IP
  3. e96

    e96 Active Member

    Messages:
    299
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    80
    #3
    you probably want the first line in the code below

    getcwd() returns the absolute path of the directory you're in. Basename gets just the innermost folder from that.

    
    echo basename(getcwd());
    echo '<br />';
    
    echo getcwd();
    
    echo '<br />';
    echo $_SERVER['PHP_SELF'];
    
    
    PHP:
     
    e96, Dec 29, 2008 IP
  4. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #4
    This code outputs absolute directory path to a file it's embedded to:

    
    
    $mydir = dirname(__FILE__);
    echo $mydir;
    
    
    PHP:
     
    wmtips, Dec 29, 2008 IP