Home >Backend Development >PHP Tutorial >How to get absolute path in PHP script
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.
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!