If you ever wanted to know the file and directory names that you are working upon, this piece of code might help you.
<?php
// __FILE__ represents C:\xampp\htdocs\dirname.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
echo 'Basename of current directory: '.'<b>'.basename(dirname(__FILE__)).'</b><br><br>'; //returns htdocs
$arrStr = explode("/", $_SERVER['SCRIPT_NAME'] );
$arrStr = array_reverse($arrStr );
echo("This Script name is: " . $arrStr[0]);
?>
<?php
// __FILE__ represents C:\xampp\htdocs\dirname.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
echo 'Basename of current directory: '.'<b>'.basename(dirname(__FILE__)).'</b><br><br>'; //returns htdocs
$arrStr = explode("/", $_SERVER['SCRIPT_NAME'] );
$arrStr = array_reverse($arrStr );
echo("This Script name is: " . $arrStr[0]);
?>
Comments
Post a Comment