: This article mainly introduces the _ FILE _ constant of PHP. if you are interested in the PHP Tutorial, refer to it. Today I encountered the constant _ FILE _ in PHP.
I checked it online. Summarizes the following rules.
The dirname (_ FILE ___) function returns the path where the script is located.
For example, file B. php contains the following content:
1
If B. php is a. php file in another directoryRequireOrInclude.
The content of the variable $ 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 and returns the parent directory of the current directory as usual.
In this way, the directory at the upper level is obtained.
Include the files to obtain the upper-level Directory
Include(Dirname (_ FILE _). '/../filename. php ');
The above introduces the _ FILE _ constant of PHP, including The require and include content, and hopes to help those who are interested in PHP tutorials.