The _ FILE _ constant in php returns the complete path of the FILE and the FILE name. dirname (_ FILE ___) function returns the path where the script is located. The _ FILE _ constant in php returns the complete FILE path and FILE name.
The dirname (_ FILE ___) function returns the path where the script is located.
For example, file B. php contains the following content:
$ Basedir = dirname (_ FILE __);
?>
If B. php is referenced by the. php file require or include in another directory.
Variable? The content of $ basedir is still the path of the folder where B. php is located.
Instead of the directory where the. php file is located.
Dirname (_ FILE _) usually returns a directory structure from the current directory of the FILE to the root directory of the system.
The current file name is not returned.
Dirname (_ FILE _) may also return a. (current directory)
[The reason is that the B. php file is in the default WEB directory where http. conf or PHP is used to configure the development environment.
For example, WEB_ROOT is: "C:/root/www/".]
B. php file path: "C:/root/www/B. php ".
Usage tips,
If you repeat the command, you can raise the directory to a higher level:
For example :? $ D = dirname (_ FILE __));
In fact, a directory is used as a parameter to dirname (), because the last Directory returned by dirname () does not contain \ or/
Therefore, we can think that dirname () treats the bottom directory as a file name.
The upper-level Directory of the current directory.
Include the files to obtain the upper-level Directory
Include (dirname (_ FILE _). '/../filename. php ');
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.