How to get absolute path in PHP script

不言
Release: 2023-04-05 09:18:02
Original
5144 people have browsed it

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");
?>
Copy after login

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");
?>
Copy after login

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__;
?>
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!