fairytailmaintheme php dirname__FILE__ gets the absolute path of the current file

WBOY
Release: 2016-07-29 08:45:46
Original
1339 people have browsed it

For 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:


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 located, result: D: www
echo dirname(dirname(__FILE__)); // Get the upper directory name of the current file, result: D:
?>


Use Method tip,
dirname(__FILE__) gets the absolute path of the current file, which means that 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 /
, so 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. By repeating this way, you will get its upper-level directory.
Include 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 name of the directory above the file.
dirname(__FILE__); What you get is the name of the directory where the file is.

The above introduces fairytailmaintheme php dirname__FILE__ to get the absolute path of the current file, including fairytailmaintheme content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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