Saturday, November 20, 2010

PHP: Get current directory name

You can easily get the current directory name at where the script is currently running. The below code will print the current directory name into screen.


$directory = dirname(__FILE__);
print $directory;


How the script works? Here __FILE__ holds the name of the currently executing file. And using finction dirname() its extracting the directory name component from it.

That means if your script name is "test.php", then __FILE__ has something like "c:\work\test.php". The function dirname() just removing that test.php from it, and returning "C:\work\"

No comments:

Get function name programaticaly - Python

This little piece of code will help you to get the function name programatically. This is very helpful when you are implementing the debug...