Php current directory of file
I have a php page inside a folder on my website. Show I need to add the name of the current directory into a variable for example:
Is this possible?
hakre 187k48 gold badges419 silver badges803 bronze badges asked Apr 3, 2012 at 16:20
Satch3000Satch3000 45.1k86 gold badges211 silver badges345 bronze badges
or
or (PHP5)
http://php.net/manual/en/function.getcwd.php http://php.net/manual/en/function.dirname.php You can use In your case, I'd say you are most likely looking to use Eg:
In your
That way when common.php is
Oliver Nybo 5501 gold badge8 silver badges22 bronze badges answered Apr 3, 2012 at 16:21
Andreas WongAndreas Wong 58.5k19 gold badges105 silver badges123 bronze badges 5 To get only the name of the directory where script executed:
answered Aug 1, 2014 at 5:31
You can use Example:
George 2,78217 silver badges29 bronze badges answered Mar 14, 2013 at 10:35
2
answered Sep 28, 2013 at 19:03
1 Actually I found the best solution is the following:
if your dir is www\var\path\ Current_Path then this returns Current_path answered Mar 24, 2013 at 1:42
AndrewAndrew 711 silver badge1 bronze badge 1
libs/images/index.php
Oliver Nybo 5501 gold badge8 silver badges22 bronze badges answered Aug 16, 2016 at 0:28
MickyMicky 1073 bronze badges 0 To get the names of current directory we can use For example if I am calling a class, from where these two functions are invoked and the class exists in some answered Jan 1, 2021 at 4:32
I use this line to get the actual file directory name without the path. (For windows)
I changed it a bit to work on Linux also
answered Sep 30, 2021 at 8:44
basename(getcwd()); // returns only the current working dir name. answered Mar 4 at 9:06
1 How can get current working directory in PHP?Use the getcwd() Function to Get the Current Directory Name in PHP. The getcwd() function gives the current working directory. The returned value is a string on success. The function does not take any parameters.
What is __ DIR __ in PHP?The __DIR__ can be used to obtain the current code working directory. It has been introduced in PHP beginning from version 5.3. It is similar to using dirname(__FILE__). Usually, it is used to include other files that is present in an included file.
How do I view a directory in PHP?PHP scandir() Function
$b = scandir($dir,1);
What is dirname (__ file __) in PHP?dirname(__FILE__) allows you to get an absolute path (and thus avoid an include path search) without relying on the working directory being the directory in which bootstrap. php resides. (Note: since PHP 5.3, you can use __DIR__ in place of dirname(__FILE__) .)
|