For example, the current file is placed under (d:www), and the file name is test.php.
The tested code is as follows:
Copy code The code is as follows:
echo __FILE__ ; // Get the absolute address of the current file, result: D:wwwtest.php
echo dirname(__FILE__); // Get the absolute directory where the current file is, result: D:www
echo dirname(dirname(__FILE__) ); //Get the upper directory name of the current file, result: D:
?>
Usage tips,
dirname(__FILE__) gets the current file The absolute path, that is to say, the search speed is the fastest compared to the relative path.
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 to
the upper-level directory of the current directory as usual. Repeat this to get its upper-level directory.
contains the file that got the upper-level directory
include(dirname(__FILE__).'/ ../filename.php');
The path of __FILE__ is the file where the current code is located
dirname(dirname(__FILE__)); What you get is the directory name above the file
dirname(__FILE__); What you get is the directory name of the layer where the file is located
http://www.bkjia.com/PHPjc/323767.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323767.htmlTechArticleFor example, the current file is placed under (d:www), and the file name is test.php. The test code is as follows: Copy the code The code is as follows: ?php echo __FILE__; // Get the absolute address of the current file, the result...