For example, the current file is placed under (d:\www\) and the filename is test.php.
The code for the test is as follows:
Copy Code code as follows:
<?php
Echo __file__; Get the absolute address of the current file, result: D:\www\test.php
echo dirname (__file__); Gets the absolute directory where the current file is located, as a result: D:\www\
Echo dirname (DirName (__file__)); Gets the top level directory name of the current file, as a result: d:\
?>
Using method hints,
DirName (__file__) takes the absolute path of the current file, which means that the lookup speed is the fastest compared to the relative path.
If you repeat, you can elevate the directory up one level:
For example: $d = DirName (dirname (__file__));
The fact is that a directory for dirname () to do the parameters. Because DirName () returns the last directory without \ or/
So when you reuse it you can assume that dirname () treats the lowest directory as a filename. Return as usual
The parent directory of the current directory. So the repetition gets the directory of its upper level.
Contains files that get a previous level of directory
Include (DirName (__file__). ' /.. /filename.php ');
The __file__ path is the file where the current code resides
DirName (DirName (__file__)); Got a directory name on the file.
DirName (__file__): The name of the directory in which the file resides
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.