Get Current Directory from PHP

Yes, I’m lazy because if I want to manual, I’ll find a method to find current directory instead of reinventing the wheel. Hehehe, so, here’s what I do to find current directory :

echo dirname(__FILE__);

Now, I have new post for my blog :D.

Update: As comments from readers, you can also use getcwd() to get equal result.

Author: Arief Bayu Purwanto

Hello, my name is Arief Bayu Purwanto, a 24 years old father of a beautiful daughter. Interested in online programming, linux, games, and reading. Currently working on kapanlagi.com as junior developer. I live in a relatively quite and cool place called Malang. I'm available for some freelance stuff as well as some consulting job. You can see my portofolio for some previous task I've finished and some other information related to my capability. Btw, I'm plurking here.

  • Wow it’s thats easy. Thanks!
    Any disadvantages to this way?

  • Wow it’s thats easy. Thanks!
    Any disadvantages to this way?

  • #keith: so far nothing is wrong with this code.

  • #keith: so far nothing is wrong with this code.

  • Ryan Pritchard

    Is there anyway to get just the directory?

    for example:

    http://www.internet.com/DIRECTORY/page.php

    all i need to extract is DIRECTORY, but havent found anyway of doing this yet.

    Many thanks in advance.

    Ryan

  • Ryan Pritchard

    Is there anyway to get just the directory?

    for example:

    http://www.internet.com/DIRECTORY/page.php

    all i need to extract is DIRECTORY, but havent found anyway of doing this yet.

    Many thanks in advance.

    Ryan

  • Ryan Pritchard

    P.S I meant to say I need the directory of what the clients browser would see, and not my server path

  • Ryan Pritchard

    P.S I meant to say I need the directory of what the clients browser would see, and not my server path

  • #Ryan: you can use this PHP class http://www.phpclasses.org/browse/file/3008.html

  • #Ryan: you can use this PHP class http://www.phpclasses.org/browse/file/3008.html

  • Ryan Pritchard

    Thanks Arief

    I tried out the script and it was a success, but I have decided to just declare the part as a fixed variable, as it makes my other scripts a lot easier to tidy up,

    Many thanks.

    Ryan

  • Ryan Pritchard

    Thanks Arief

    I tried out the script and it was a success, but I have decided to just declare the part as a fixed variable, as it makes my other scripts a lot easier to tidy up,

    Many thanks.

    Ryan

  • #Ryan:Yeah, your welcome.

  • #Ryan:Yeah, your welcome.

  • getcwd() ??

    silent:Mwahahahaha, like I sad, I’m reinvent the whell :)). Thanks for the information.

  • getcwd() ??

    silent:

    Mwahahahaha, like I sad, I’m reinvent the whell :)). Thanks for the information.

  • Comrade.Cid theKillerRabbit

    thanks a bunch – this called gave me exactly what i needed: the actual current location, as opposed to the overall workspace 😛

  • Prashant Renge

    Nothing is important !

    only Google adds.

  • getcwd() ;

    or
     
    echo __DIR__;

  • Benja

    echo end(explode(‘/’,getcwd()));

    saludos!