Phpdirname (_ FILE _) and _ FILE _ constants. In php, dirname () and _ FILE _ are our constants. This article will give you a detailed introduction to some issues in the use of dirname () and _ FILE _ constants, if you are interested, go to the reference page. Dirn in php, dirname () and _ FILE _ are our constants. This article will introduce dirname () in detail () and _ FILE _ constants in the use process of some issues, interested friends can go to the reference.
Dirname () function
String dirname (string $ path)
A string containing a full path pointing to a file is provided. This function returns the directory name after removing the file name.
In Windows, both slash (/) and backslash () can be used as directory separators. It is a slash (/) in other environments (/).
Example #1 dirname ()
Example
| The code is as follows: |
|
|
Echo dirname ("c:/testweb/home. php ");
Echo dirname ("/testweb/home. php ");
?>
Output:
C:/testweb
/Testweb |
_ FILE __
The complete file path and file name. If it is used in a file to be included, the file name to be included is returned.
Dirname (_ file __)
_ FILE _: a PHP magic constant. it returns the complete path and FILE name of the currently executed PHP script, including an absolute path.
1) the dirname (_ FILE _) function returns the path of the script. Update network
For example, file B. php contains the following content:
| The code is as follows: |
|
|
$ Basedir = dirname (_ FILE __);
Echo $ basedir
// An absolute path of the file will be printed on the page!
?> |
The result of my test is: E: websiteothertestcms.
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. The php file path is "C:/root/www/B. php". the usage prompt is displayed. if you repeat it once, you can upgrade 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 parent directory of the current directory. in this way, the directory at the upper level is obtained. include (dirname (_ FILE __). '/.. /filename. php ');
2. How to combine php files with html files
| The code is as follows: |
|
If ($ reguser! = ""){
Echo "Submit Photo
";
Echo "Log Out ";
} Else {
Echo "Login ";
}
?> |
Values () and _ FILE _ are our constants. This article introduces dirname () and _ FILE _ constants in detail, if you are interested, go to the reference page. Dirn...