Results 1 to 3 of 3

Thread: finding absolute path to current script / without current script

  1. #1
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default finding absolute path to current script / without current script

    Hi,

    I need to figure out how to determine the absolute path to the directory containing the currently executing script:
    PHP Code:
    <?php
    $absolute 
    $_SERVER['DOCUMENT_ROOT'].$_SERVER['PHP_SELF'];
    ?>
    will get me the path including the file name, but I want it without. Like so:
    Code:
    www.example.com/path/to/
    and not like so:
    Code:
    www.example.com/path/to/file.php
    If you have the answer, I'd love to hear it

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    PHP might have something built in for this, but here's something that should work:

    You can use one $_SERVER command, instead of two in this instance

    PHP Code:
    <?php

    $end 
    strrpos($_SERVER['SCRIPT_FILENAME'], '/'); // Finds last slash

    echo substr($_SERVER['SCRIPT_FILENAME'], 0$end 1); 

    // returns file path with / added on the end, remove + 1 to take this out

    ?>

  3. The Following User Says Thank You to Schmoopy For This Useful Post:

    traq (08-30-2009)

  4. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    hey, cool. I was up late last night looking for a built-in PHP function, but couldn't figure it out. Thanks!

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
  •