Page 1 of 1

detecting directory

Posted: Mon Dec 29, 2008 4:00 am
by m2babaey
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

Re: detecting directory

Posted: Mon Dec 29, 2008 4:34 am
by requinix
__FILE__ is a magic constant that gives you the full path to the file it's used it. With some combination of dirname and basename...

Code: Select all

// __FILE__ is /path/to/file.php
echo basename(__FILE__); // file.php
echo basename(dirname(__FILE__)); // to
echo basename(dirname(dirname(__FILE__))); // path
echo basename(dirname(dirname(dirname(__FILE__)))); // .