Transferred from: https://www.cnblogs.com/hf8051/p/4613103.html
getcwd () : Shows the directory in which the file was called (run)
__dir__ : The current content is written in which file to display this file directory
__file__ : The current content is written in which file to display this file directory + file name
Thus
GETCWD () and __dir__ return the absolute path where the file is located, but not the name of the file itself.
__FILE__ is the absolute path where the file is located, but with the name of the file itself.
The following is a reference to Baidu
Create the file test.php in ch06. The directory is: ch06\test.php
The contents are as follows:
<?php$a= getcwd ();//The value of variable A is d:\php\zend6.1\ch6$b=__file__;//the value of variable B is d:\php\zend6.1\ch6\test.php?>
The folder Admincp folder is created under the CH06 project below. Create the file fff.php under the Admincp folder. The directory is: ch06\admincp\fff.php
The code is as follows
<?phpinclude_once '. /test.php '; echo $a;//The value in variable A is D:\php\zend6.1\ch6\admincpecho ' <pre> '; echo $b;//The value in variable B is D:\php\zend6.1\ch6\ Test.php?>
This shows that the test.php file is included in another file. The path variable A of test.php obtained with GETCWD () in the test.php file changes after it has been contained. The directory structure is added to the ffff.php directory ADMINCP, so • __file__ better when locating files
Example
<?phpdefine (' Path_root ', ($PATH _root=dirname (__file__))? $PATH _root: ' ... '); $PATH _admincp=path_root. ' \ADMINCP '; $PATH _picture=path_root. ' \pciture '; $PATH _admincp_include= $PATH _admincp. ' \include ';? ><?phpinclude_once dirname (__file__). ' /.. /.. /path.php '; include_once path_root. " /con_ini.php ";? >
PHP-Fetch path: GETCWD (), __dir__, __file__ difference "turn"