php dirname(__FILE__) gets the absolute path of the current file_PHP tutorial

WBOY
Release: 2016-07-21 15:27:17
Original
832 people have browsed it

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

www.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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template