__FILE__, is the full path and file name of the returned file. If used in the include file, the include file name is returned. Since PHP 4.0.2, __file__ always contains an absolute path, and the previous version sometimes contains a relative path. DirName (__file__), returns a partial path to the current file path, which is to remove the filename.
Demo Code:
Copy Code code as follows:
<?php
Gets the current path + filename of the file
Echo __file__;
Echo ' <BR> ';
Gets the current path of the file
echo dirname (__file__);
Echo ' <BR> ';
Get the directory path to the file at the top level
Echo dirname (DirName (__file__));
?>
Run Result:
Copy Code code as follows:
D:\wamp\www\index.php
D:\wamp\www
D:\wamp
__file__ is very good, you can get the current path of the file, even if the include does not change, can be used as the absolute path of the Web site on the server, other directories as the base distribution.