Web Hosting Talk







View Full Version : Finding the name of the current sub-directory


VolkNet
06-09-2005, 05:26 PM
Hey I have a script that installs a .htaccess file for the client but I have a small problem.

How can I determine the name of a subdirectory a script resides in?

For example script is at: http://mysite.com/resources/myscript.php

How could I find that it's at resources/ ?

Thank you very much.

VolkNet
06-09-2005, 08:32 PM
Got it to work finally.

Heres the code - if you see any errors tell me :)

<?php
function sub_dir_func($url, $base){
$sub_dir = explode("/",$url);
$return_url = '';
$counted = count($sub_dir);
if($counted > 2) {
for($i=1;$i < $counted-1; $i++){
$return_url .= $sub_dir[$i].'/';
}
$return_url = $base.'/'.$return_url;
}
else $return_url = $base.$counted;

return $return_url;
}
?>