The _ FILE _ constant of PHP encountered the constant _ FILE _ of PHP today. I checked it online. Summarizes the following rules. Dirname (_ FILE ___) & nbsp; the function returns the path where the script is located. For example, the file & nbsp; B. php & nbsp; contains the following content: & nbsp; 1 & lt ;? Php2 $ basedirdirname (_ FILE _); 3? & G PHP's _ FILE _ constant
Today I encountered the constant _ FILE _ in PHP.
I checked it online. Summarizes the following rules.
Dirname (_ FILE ___)The function returns the path where the script is located.
For example, file B. php contains the following content:
1
If B. php is referenced by the. php file require or include in another directory.
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 ');