In the file, for example: the program root directory is in: E:wampwww
1. __FILE__ The absolute path of the current file
If called in index.php, it will return E:wampwwwindex.php
The following Take a look at the directory structure of the program root directory
If __FILE__ is called in c_system_base.php, it will return:
E:wampwwwzb_systemfunctionc_system_base.php
2.dirname Return to the parent directory of the current directory or the directory where the current file is located Directory (without / at the end)
Generally used in conjunction with __FILE__
If dirname(__FILE__) is called in c_system_base.php, it will return
E:wampwwwzb_systemfunction (the file returns to the directory where it is located)
If dirname( is called) dirname(__FILE__)) then returns
E:wampwwwzb_system (the directory returns to the upper-level directory)
3.realpath() The method returns the absolute path of the current file or the path relative to the root directory
If realpath is called in c_system_base.php (__FILE__) returns
E:wampwwwzb_systemfunctionc_system_base.php
realpath('/') Returns to the root directory of the disk E:
realpath('./') Returns to the root directory E:wampwww
realpath('../' ) Returns to the superior directory relative to the program root directory
can also be used in conjunction with dirname, usually adding several relative paths../ (add / in front, that is: /../)
realpath(dirname(__FILE__)) Return E:wampwwwzb_systemfunction
realpath(dirname(__FILE__).'/../') Return E:wampwwwzb_system
realpath(dirname(__FILE__).'/../../') Return E:wampwww
Above This article introduces the dirname, realpath, and __FILE__ related to PHP paths, including related content. I hope it will be helpful to friends who are interested in PHP tutorials.