How to Get Absolute Directory Path in PHP Script
Abstract: php include(dirname(__FILE__)."/other.php")>123
PHP 4.0 introduced __FILE__ magic constant, which provides the full path and filename of the file.
To get directory path only use dirname(__FILE__). For example to include other file in same directory use:
<?php include(dirname(__FILE__)."/other.php"); ?>123<?php include(dirname(__FILE__)."/other.php");?>Later the PHP version 5.3.0 and later versions introduced a new constant called __DIR__ which is the short form of the dirname(__FILE__). You can also use this in replacement of what we used earlier.
Now, you can use above script like:
<?php include(__DIR__."/other.php"); ?>123<?php include(__DIR__."/other.php");?>To simply print the absolute directory path of PHP script located in:
<?php echo __DIR__; ?>123<?php echo __DIR__;?>