
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
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
<!DOCTYPE html> <html> <body> <?php echo dirname(__FILE__); echo "<br>"; echo __DIR__; ?> </body> </html>
Output
/home/KOq8Zd /home/KOq8Zd
- Related Articles
- C# Program to get the name of root directory
- Get all subdirectories of a given directory in PHP
- How to get root directory information in android?
- PHP – How to get or set the path of a domain?
- How to get full path of current file's directory in Python?
- Get the absolute path for the directory or file in Java
- How to get file name from a path in PHP?
- Find last Directory or file from a given path
- How to create a directory in project folder using Java?
- How to extract a part of the file path (a directory) in Python?
- Specify a path for a file or a directory in Java
- How to Zip a directory in PHP?
- PHP: Unlink All Files Within A Directory, and then Deleting That Directory
- Top Project Manager Qualifications and Career Path
- Carving Your Path to Project Management Office

Advertisements