Home  >  Article  >  Backend Development  >  How to get absolute path in PHP script

How to get absolute path in PHP script

不言
不言Original
2019-02-16 10:05:115148browse

How to get the absolute path in How to get absolute path in PHP script script? This article will introduce to you the method of obtaining the absolute path in the script in PHP. Friends in need can take a look.

How to get absolute path in PHP script

PHP 4.0 introduced the __FILE__ magic constant, which provides the full path and file name of a file.

To get the directory path, just use dirname(__FILE__). For example, to include other files in the same directory:

<?How to get absolute path in PHP script
  include(dirname(__FILE__)."/other.How to get absolute path in PHP script");
?>

Later PHP versions 5.3.0 and later introduced a new constant called __DIR__, which is a shortened form of dirname (__FILE__) . It can also be used instead of the method we used before.

Now, you can use the following method:

<?How to get absolute path in PHP script
  include(__DIR__."/other.How to get absolute path in PHP script");
?>

Just output the absolute directory path of the PHP script located in the following location:

<?How to get absolute path in PHP script
  echo __DIR__;
?>

This article is all over here For more exciting content, you can pay attention to other related column tutorials on the PHP Chinese website! ! !

The above is the detailed content of How to get absolute path in PHP script. For more information, please follow other related articles on the PHP Chinese website!

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