Understanding php dirname(__FILE__)

WBOY
Release: 2016-07-25 09:04:29
Original
1088 people have browsed it
Assume that the current file is stored under (d:www) and the file name is test.php.

Assume that the current file is stored under (d:www) and the file name is test.php.

Copy code The code is as follows:

Instructions: dirname(__FILE__) obtains the absolute path of the current file. Compared with relative paths, the search speed is the fastest. If you repeat it once, you can move the directory up a 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 / Therefore, when reused, it can be considered that dirname() treats the lowest directory as a file name. Return as usual The upper-level directory of the current directory, so that if you repeat it, you will get its upper-level directory.

Contains files from the upper-level directory:

Copy code The code is as follows: include(dirname(__FILE__).’/../filename.php’);


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