Dirname (_ file __)
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
<? PHP
$ The_full_name =__ file __;
$ The_dir = dirname (_ file __);
Echo $ the_full_name; // return/home/data/demo/test/a. php
Echo $ the_dir; // return/home/data/demo/test
?>
Home/data/demo/B. php
<? PHP Include "test/a. php ";
Echo $ the_full_name; // return/home/data/demo/
Echo $ the_dir; // return/home/data/demo/test instead of/home/data/demo/
?> Test/a. php instead of/home/data/demo/B. 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)
Dirname (_ file __)