How To Get Directory Path Only Without File Name In PHP
how to get directory path only without file name in php
how, to, get, directory, path, only, without, file, name, in, php
How To Get Directory Path Only Without File Name In PHP
Post Description: how to get directory path only without file name in php
POST# 479
Posted On: Fri Feb 29, 2008 12:01 pm
web hosting
Topic: How To Get Directory Path Only Without File Name In PHP
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.


No Repies
(0) Comments for How To Get Directory Path Only Without File Name In PHP

What do you think?

* name:  

* email:  

* Please enter comments:


Receive Replies on my Comments
(An email will be sent to you when someone replies to your comments)

Add image to comments
yes no             upload