Getting The Full Path Directory Of A File
- Forums
- PHP
- Getting The Full Path Directory Of A File
this short script helps you in getting only the full path of the location of the current file name, this is helpful when you have other scripts in your directory and then you move it somewhere else so you dont have to change the code all the time its more [2108], Last Updated: Mon Jun 24, 2024
Padaki52
Thu Oct 07, 2010
0 Comments
734 Visits
this short script helps you in getting only the full path of the location of the current file name, this is helpful when you have other scripts in your directory and then you move it somewhere else so you dont have to change the code all the time its more dynamic.
<?PHP
# SCRIPT PROVIDED BY WEBUNE.COM
# PLEASE DO NOT REMOVE THIS CREDIT
echo 'this is the full script path: '.$_SERVER['SCRIPT_FILENAME'].'<BR>';
function GetFileName($php_self){
$filename = explode("/", $php_self); // THIS WILL BREAK DOWN THE PATH INTO AN ARRAY
$filename = array_reverse($filename ); // THIS WILL MAKE THE LAST ELEMENT THE FIRST
return $filename[0];
}
echo 'The name of this file is: '.GetFileName($_SERVER['PHP_SELF']).'<BR>';
echo 'This is the full path of the directory: '.str_replace(GetFileName($_SERVER['PHP_SELF']),"",$_SERVER['SCRIPT_FILENAME']);
?>