Get Root Directory Path of a PHP project?


In order to get the root directory path, you can use _DIR_ or dirname().

The syntax is as follows −

echo _DIR_;

The second syntax is as follows−

echo dirname(__FILE__);

Both the above syntaxes will return the same result.

Example

 Live Demo

<!DOCTYPE html>
<html>
<body>
<?php
   echo dirname(__FILE__);
   echo "<br>";
   echo __DIR__;
?>
</body>
</html>

Output

/home/KOq8Zd
/home/KOq8Zd

Updated on: 12-Oct-2020

18K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements