PHPdirname () function definition and usage
The dirname () function returns the directory part of the path.
Syntax
Dirname (path) parameter description
Path is required. Specifies the path to be checked.
Description
The path parameter is a string containing a full path pointing to a file. This function returns the directory name after the file name is removed.
Example
Echo dirname ("c:/testweb/home. php ");
Echo dirname ("/testweb/home. php ");
?>
Output:
C:/testweb
/Testweb
Php defines a very useful constant, that is
_ FILE __
This internal constant is the complete path (path + file name) of the current php program ).
Even if this FILE is referenced by another FILE (include or require), __file _ is always the complete path of the FILE where it is located, rather than the full path of the FILE that references it.
See the following example:
/Home/data/demo/test/a. php
Echo dirname ("c:/testweb/home. php ");
Echo dirname ("/testweb/home. php ");
?>
Home/data/demo/B. php
Echo dirname ("c:/testweb/home. php ");
Echo dirname ("/testweb/home. php ");
?>
Simply put:
_ FILE _ return current path + FILE name
Dirname (_ FILE _) returns the path of the current FILE path.
Dirname (_ FILE _); the directory name (excluding the last "/" number) at the top of the FILE is obtained)
For example, if the current file is/home/data/demo/test. php
The complete path is/home/data/demo/test. php.
Dirname (_ FILE _) to obtain the path section/home/data/demo (no "/" number is displayed later)