Home  >  Article  >  Backend Development  >  PHP implementation code to obtain the absolute path of the current file

PHP implementation code to obtain the absolute path of the current file

WBOY
WBOYOriginal
2016-07-25 09:00:101172browse
  1. $basedir = dirname(__FILE__);
  2. echo $basedir;
  3. //The absolute path to this file will be printed on the page!
  4. ?>
Copy code

Can be used later

  1. define('ROOT', dirname(__FILE__));
  2. require_once ROOT.'/config/conf_mysql.php';
Copy code

Import files

Several commonly used PHP "Magic constants" Name Description __LINE__ The current line number in the file. __FILE__ The full path and file name of the 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. __FUNCTION__ function name (new in PHP 4.3.0). Since PHP 5 this constant returns the name of the function as it was defined (case sensitive). In PHP 4 this value is always lowercase. __CLASS__ The name of the class (new in PHP 4.3.0). Since PHP 5 this constant returns the name of the class when it was defined (case sensitive). In PHP 4 this value is always lowercase. __METHOD__ The method name of the class (newly added in PHP 5.0.0). Returns the name of the method when it was defined (case-sensitive).

Please have a firm grasp of the above and use them more in programming skills.



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