Get Root Directory Path of a PHP project?

PHPServer Side ProgrammingProgramming

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
raja
Published on 12-Oct-2020 12:22:16
Advertisements