DirName (__file__)
A useful constant is defined in PHP, which is
__file__
The default constant is the full path (path + filename) of the current PHP program.
Even if the file is referenced by another file (include or require), __file__ is always the full path to the file it resides in, not the full path to the file that references it.
Take a look at the following example:
/home/data/demo/test/a.php
< PHPBR style= ' Font-size:16px;font-style:normal;font-weight:normal;color:rgb (a), '/> $the _full_ name=__file__;
$the _dir=dirname (__file__);
echo $the _full_name; Back to/home/data/demo/test/a.php
echo $the _dir; Back to/home/data/demo/test
?<
home/data/demo/b.php
< PHP include Testaphpbr style= ' Font-size:16px;font-style:normal;font-weight:normal;color:rgb (110, 110, 110); '/ >echo $the _full_name; Back to/home/data/demo/
echo $the _dir; Return/home/data/demo/test instead of/home/data/demo/
<test/a.php, not/home/data/demo/b.php.
To put it simply:
__FILE__ returns the current path + file name
DirName (__file__) returns the path portion of the current file path
DirName (DirName (__file__)); Gets the file on the top of the directory name (does not include the last "/" number)
For example, if the current file is/home/data/demo/test.php, the
__FILE__ get is the full path is/home/data/demo/test.php, and
DirName (__file__) Gets the path part that is the/home/data/demo (no "/" number behind)
</p></div></p></div>
Summary of Use of dirname (__file__)