dirname(FILE_) The function returns the path where the script is located.
For example, the file b.php contains the following content:
<?php $basedir = dirname(FILE); ?>
If b.php is used by a.php file in another directory require or include Go to and quote .
The content of the variable $basedir is still the path to the folder where b.php is located.
Instead of changing to the directory where the a.php file is located.
dirname(FILE) generally returns a directory structure from the current directory where the file is located to the system root directory.
The current file name will not be returned.
dirname(FILE) may also return a . (current directory)
[The reason is that the b.php file is in the default WEB directory of http.conf or PHP Configuring the development environment .
For example, WEB_ROOT is: "C:/root/www/".]
b.php file path is: "C:/root/www/b.php".
Usage tips,
If you repeat it once, you can move the directory up a level:
For example: $d = dirname(dirname(FILE));
In fact, you give a directory as a parameter to dirname(). Because dirname() returns the last directory without \\ or /
, when it is used repeatedly, it can be considered that dirname() treats the lowest directory as a file name. Return
the upper-level directory of the current directory as usual. Repeat this to get its upper-level directory.
Contains the files that get the upper-level directory
include(dirname(FILE).'/../filename.php');
2. How to use PHP files and html files together
<?php if($reguser != ""){ echo"Submit Photo "; echo"Log Out"; }else{ echo"Login"; } ?>
FILE represents the absolute path of the current file including the file name, dirname(FILE) represents the absolute path of the current file, basename(FILE) represents The file name of the current file, dirname(FILE)."/f/".basename(FILE) means a file with the file name dirname(FILE) in the f directory under the directory where the current file is located. require means that the file is included in this file.
1) The dirname(FILE_) function returns the path where the script is located.
For example, the file b.php contains the following content:
$basedir = dirname(FILE);
?>
If b.php is replaced by a in another directory. PHP file require or include to quote.
The content of the variable $basedir is still the path to the folder where b.php is located.
Instead of becoming the directory where the a.php file is located.
2) dirname(FILE) generally returns a directory structure from the current directory where the file is located to the system root directory.
Will not return the current file name.
dirname(FILE) may also return one. (current directory)
[The reason is that the b.php file is in http.conf or the default WEB directory of the PHP configuration development environment.
For example, WEB_ROOT is: "C :/root/www/".]
The path to the b.php file is: "C:/root/www/b.php".
3) Usage tips,
If repeated You can raise the directory to a higher level:
For example: $d = dirname(dirname(FILE));
In fact, you just give a directory as a parameter to dirname(). Because dirname() returns the last directory without \\ or /
, so when it is used repeatedly, it can be considered that dirname() treats the lowest directory as a file name. Return as usual
The superior directory of the current directory. Repeat this to get its superior directory.
The above is the detailed content of Detailed explanation of __FILE__ constant and dirname() instance usage in php. For more information, please follow other related articles on the PHP Chinese website!