PHP constant dirname (_ file _) _ FILE _: a PHP magic constant. it returns the complete path and file name of the currently executed PHP script, including an absolute path.
The dirname (_ FILE _) function returns the path of the script.
For example, the index. php file contains the following content:
$ Basedir = dirname (_ FILE __);
Echo $ basedir; // The absolute path of the file is printed on the page!
?>
Test result: E: \ wamp \ www \ test
If index. php is referenced by the test. php file require or include in other directories. The content of the variable $ basedir is the path of the folder where index. php is located, rather than the directory where the test. php file is located.
Dirname (_ FILE _); the directory name at the top of the FILE is obtained.
Extended knowledge points:
DIRECTORY_SEPARATOR: the built-in variable DIRECTORY_SEPARATOR of PHP is a command for displaying system separators. DIRECTORY_SEPARATOR is an internal constant of php and can be directly used without any definition or inclusion.
This PHP built-in command returns \ on windows, and returns/on linux or unix-like, it is usually used when defining the path containing files or uploading and storing directories.
Example:
// PHPCMS framework path
Define ('PC _ path', dirname (_ FILE _). DIRECTORY_SEPARATOR );