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:
Post Tags: how, to, get, directory, path, only, without, file, name, in, php
This Post Has Been Viewed 555 Times Since Fri Feb 29, 2008 10:30 pm Posted By hostman with 1 replies
Next Post »» how to check if file exists in a directory with PHP
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.

Leave Your Comments     [ dejar commentarios ]
  * Name     [nombre]

  * eMail (will not be published)     [coreo electronico]

* Enter Your Reply or Comments:    [commentarios]


Add Picture To Comments         [incluir foto]
YES NO             upload
Receive Replies on my Comments (An email will be sent to you when someone replies to your comments)

     

Comments and replies About How To Get Directory Path Only Without File Name In PHP




:: 1 :: #47288 - Reply By jannable On Thu Mar 27, 2008 5:05 am
what about using dirname? would that not accomplish the same thing?
echo dirname($_server['php_self']); ca.php.net/manual/en/function.dirna