Freelancer's Playground! New knowledges every now and then

8May/0720

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.

  • http://www.keith-hair.com/ Keith

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

  • http://www.keith-hair.com Keith

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

  • http://bayu.freelancer.web.id/ Arief Bayu Purwanto

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

  • http://bayu.freelancer.web.id Arief Bayu Purwanto

    #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

  • http://bayu.freelancer.web.id/ ariefbayu

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

  • http://bayu.freelancer.web.id Arief Bayu Purwanto

    #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

  • http://bayu.freelancer.web.id/ ariefbayu

    #Ryan:Yeah, your welcome.

  • http://bayu.freelancer.web.id Arief Bayu Purwanto

    #Ryan:Yeah, your welcome.

  • http://dsin.blogspot.com/ dsin

    getcwd() ??

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

  • http://dsin.blogspot.com dsin

    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 :P

  • Prashant Renge

    Nothing is important !

    only Google adds.

  • http://unnikrishnan.myopenid.com/ unnikrishnan

    getcwd() ;

    or
     
    echo __DIR__;

  • Benja

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

    saludos!