__FILE__: called the PHP Magic Constant, returns the full path and file name of the currently executing PHP script, including an absolute path.
The dirname (__file__) function returns the path where the script is located.
For example, the file index.php contains the following content:
$basedir = DirName (__file__);
Echo $basedir; An absolute path to the file will be printed on the page!
?>
I did the test to get the result: E:\wamp\www\test
If index.php is referenced by a test.php file require or include in another directory. The content of the variable $basedir is also the path to the folder where the index.php resides, rather than the directory where the test.php file resides.
DirName (DirName (__file__)); The first level of directory name is obtained.
Expand Knowledge Points:
Directory_separator:php's built-in variable directory_separator is a command that displays the system delimiter, Directory_separator is the internal constant of PHP, and does not require any definition or inclusion to be used directly.
This PHP built-in command, which returns \ on Windows and returns on Linux or Unix-like, is a common distinction that is usually used when defining a file path or uploading a saved directory.
Cases:
Phpcms Frame Path
Define (' Pc_path ', DirName (__file__). Directory_separator);