getcwd () : Displays the directory in which the file is called
__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
<? PHP include_once ‘.. /test.php '; Echo $a; // the value in variable A is D:\PHP\ZEND6.1\CH6\ADMINCP Echo ' <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_oncePath_root. " /con_ini.php ";?>
PHP-Fetch path: GETCWD (), __dir__, __file__ difference