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;
Is this possible?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
or
or (PHP5)
http://php.net/manual/en/function.getcwd.php
http://php.net/manual/en/function.dirname.php
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
getcwd(),dirname(__FILE__)is more useful when you have a file that needs to include another library and is included in another library.Eg:
In your
common.phpyou need to use functions ineditor.php, so you usecommon.php:main.php:That way when common.php is
require'dinmain.php, the call ofrequire_onceincommon.phpwill correctly includeseditor.phpinimages/editor.phpinstead of trying to look in current directory wheremain.phpis run.