I have a php page inside a folder on my website.
I need to add the name of the current directory into a variable for example:
$myVar = current_directory_name;
getcwd(); or dirname(__FILE__); or (PHP5) basename(__DIR__)
You can use
basename() to get the trailing part of the path :)
In your case, I'd say you are most likely looking to use
dirname(__FILE__) is more useful when you have a file that needs to include another library and is included in another library.
main.php libs/common.php libs/images/editor.php
common.php you need to use functions in
editor.php, so you use
require_once dirname(__FILE__) . '/images/editor.php';
That way when common.php is
main.php, the call of
common.php will correctly includes
images/editor.php instead of trying to look in current directory where
main.php is run.