The dirname() function returns the directory name from the specified path. If the path has no slashes, a dot ('.') is returned. This indicates the current directory.
Syntax
dirname(file_path)
Parameters
file_path − File to be specified.
Return
The dirname() function returns the path of the directory.
Example
<?php $file_path = "D:/amit/java.docx"; $dir_name = dirname($file_path); echo "Name of the directory: $dir_name\n"; ?>
Output
Name of the directory: D:/amit
Let us see another example.
Example
<?php $file_path = "/amit/java.docx"; $dir_name = dirname($file_path); echo "Name of the directory: $dir_name\n"; ?>
Output
Name of the directory: /amit