Note: __FILE__ represents "F:\Program Files\XAMPP\htdocs\dirname.php" in my system.
php code:
<?php
echo 'The current file: '.'<b>'.__FILE__.'</b><br><br>';
echo 'DIR name using dirname(__FILE__): '.'<b>'.dirname(__FILE__).'</b><br><br>'; // returns C:\xampp\htdocs
echo 'Current working directory using getcwd(): '.'<b>'.getcwd().'</b><br><br>'; // returns C:\xampp\htdocs
echo 'Basename of current file: '.'<b>'.basename(__FILE__).'</b><br><br>'; //returns dirname.php
$arrStr = explode("/", $_SERVER['SCRIPT_NAME'] );
$arrStr = array_reverse($arrStr );
echo "This is yet another way to get this script name: ".'<b>'.$arrStr[0].'</b><br><br>';
echo 'Basename of current directory: '.'<b>'.basename(dirname(__FILE__)).'</b>'; //returns htdocs
?>
Output: click image to enlarge
php code:
<?php
echo 'The current file: '.'<b>'.__FILE__.'</b><br><br>';
echo 'DIR name using dirname(__FILE__): '.'<b>'.dirname(__FILE__).'</b><br><br>'; // returns C:\xampp\htdocs
echo 'Current working directory using getcwd(): '.'<b>'.getcwd().'</b><br><br>'; // returns C:\xampp\htdocs
echo 'Basename of current file: '.'<b>'.basename(__FILE__).'</b><br><br>'; //returns dirname.php
$arrStr = explode("/", $_SERVER['SCRIPT_NAME'] );
$arrStr = array_reverse($arrStr );
echo "This is yet another way to get this script name: ".'<b>'.$arrStr[0].'</b><br><br>';
echo 'Basename of current directory: '.'<b>'.basename(dirname(__FILE__)).'</b>'; //returns htdocs
?>
Output: click image to enlarge
Comments
Post a Comment