To find the parent directory of a file in PHP, you can use the dirname()
function.
main.php109 chars4 lines
In the example above, we pass the file path to the dirname()
function, which returns the parent directory of the file. The resulting $parentDir
variable contains the path to the parent directory.
You can also use dirname()
with the __FILE__
constant to get the parent directory of the current PHP file:
main.php49 chars3 lines
This will output the path of the parent directory of the current PHP file.
gistlibby LogSnag