Home > Backend Development > PHP Tutorial > PHP path related dirname, realpath, __FILE__, dirnamerealpath_PHP tutorial

PHP path related dirname, realpath, __FILE__, dirnamerealpath_PHP tutorial

WBOY
Release: 2016-07-12 08:57:28
Original
823 people have browsed it

PHP path related dirname, realpath, __FILE__, dirnamerealpath

​For example: the program root directory is in: E:wampwww

1. __FILE__ The absolute path of the current file

If called in index.php, it will return E:wampwwwindex.php

Let’s take a look at the directory structure of the program root directory

If __FILE__ is called in c_system_base.php it returns:

E:wampwwwzb_systemfunctionc_system_base.php

2.dirname Returns the parent directory of the current directory or the directory where the current file is located (without / at the end)

Generally used in conjunction with __FILE__

If dirname(__FILE__) is called in c_system_base.php, it will return

E:wampwwwzb_systemfunction (the file returns to the directory where it is located)

If dirname(dirname(__FILE__)) is called, it returns

E:wampwwwzb_system (the directory returns to the upper directory)

realpath() method returns the absolute path of the current file or the path relative to the root directory

If realpath(__FILE__) is called in c_system_base.php, it will return

E:wampwwwzb_systemfunctionc_system_base.php

realpath('/') Return to disk root directory E:

realpath('./') Return to the root directory E:wampwww

realpath('../') Returns the superior directory relative to the program root directory

can also be used in conjunction with dirname, usually adding several relative paths../ (add / in front, that is: /../)

realpath(dirname(__FILE__)) Return E:wampwwwzb_systemfunction

realpath(dirname(__FILE__).'/../') returns E:wampwwwzb_system

realpath(dirname(__FILE__).'/../../') Return E:wampwww

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1108336.htmlTechArticlePHP path related dirname, realpath, __FILE__, dirnamerealpath ​For example: the program root directory is in: E:wampwww 1. __FILE__ The absolute path of the current file if called in index.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