- Forums
- PHP
- How To Get Directory Path Only Without File Name In PHP
This Page Contains information about How To Get Directory Path Only Without File Name In PHP By wallpaperama in category PHP with 7 Replies. [1110], Last Updated: Sat May 18, 2024
wallpaperama
Fri Feb 29, 2008
7 Comments
10771 Visits
if you want to know how you can get your file directory path only without the file name you can use this handy function i use often.
<?
function GetFileDir($php_self){
$filename = explode("/", $php_self); // THIS WILL BREAK DOWN THE PATH INTO AN ARRAY
for( $i = 0; $i < (count($filename) - 1); ++$i ) {
$filename2 .= $filename[$i].'/';
}
return $filename2;
}
echo GetFileDir($_SERVER['PHP_SELF']);
?>
so for example when i do this:
echo $_SERVER['PHP_SELF'];
OUTPUT:
/var/www/myfile.php
but i dont want the myfile.php part of it, i only need
/var/www/ part. so to do this you can use the function above and it will return this:
OUTPUT:
/var/www/
thanks for www.webune.com for their support on this.