Home  >  Article  >  Backend Development  >  Detailed explanation of dirname, realpath, __FILE__ functions related to PHP paths

Detailed explanation of dirname, realpath, __FILE__ functions related to PHP paths

PHP中文网
PHP中文网Original
2017-06-05 09:35:242273browse

In the file, for example: the program root directory is in: E:wampwww

PHP路径相关 dirname,realpath,__FILE__

1. __FILE__ The absolute path of the current file

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

The following Take a look at the directory structure of the program root directory

PHP路径相关 dirname,realpath,__FILE__

If __FILE__ is called in c_system_base.php, it will return:

E:wampwwwzb_systemfunctionc_system_base.php

2.dirname Return to the parent directory of the current directory or the directory where the current file is located Directory (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( is called) dirname(__FILE__)) then returns

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

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

If realpath is called in c_system_base.php (__FILE__) returns

E:wampwwwzb_systemfunctionc_system_base.php

realpath('/') Returns to the root directory of the disk E:

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

realpath('../' ) Returns to 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__).'/../') Return E:wampwwwzb_system

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

Above This article introduces the dirname, realpath, and __FILE__ related to PHP paths, including related content. I hope it will be helpful to friends who are interested in PHP tutorials.

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