Home  >  Article  >  Backend Development  >  PHP Get file path (flexible application __FILE__)_PHP tutorial

PHP Get file path (flexible application __FILE__)_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:12:43741browse

__FILE__ is the full path and file name of the returned file. If used in an include file, returns the include file name. As of PHP 4.0.2, __FILE__ always contains an absolute path, while versions before that sometimes contained a relative path. dirname(__FILE__), returns the partial path of the current file path, that is, removing the file name.

Demo code:

Copy code The code is as follows:

// Get the current path + file name of the file
echo __FILE__;
echo '
';
// Get the current path of the file
echo dirname(__FILE__);
echo '
';
/ / Get the upper-level directory path of the file
echo dirname(dirname(__FILE__));
?>

Run result:

Copy code The code is as follows:

D:wampwwwindex.php
D:wampwww
D:wamp

__FILE__ is very useful. It can get the current path of the file. It will not change even if it is included. It can be used as the absolute path of the website on the server, and other directories will be distributed based on this.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326615.htmlTechArticle__FILE__ is the full path and file name of the returned file. If used in an include file, returns the include file name. Since PHP 4.0.2, __FILE__ always contains an absolute path, and in...
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