|
Posted by Steve on 04/12/07 17:03
alright, so i've got some free-time. ;^)
i'm guessing your function recurses to 1) find that a directory exists and
2) find out how deeply nested it is. based on that, this should work just
fine:
<?
function combinePath(&$directory, $index, $path)
{
$directory = $path . '/' . $directory;
}
function getDirectories($path, &$tree = array())
{
$tree[$path] = $path;
$directory = opendir($path);
while (($fileName = readdir($directory)) !== false)
{
if ($fileName == '.' || $fileName == '..'){ continue; }
if (!is_dir($fileName)){ continue; }
$directories[] = $fileName;
}
closedir($directory);
if (!$directories){ return $tree; }
array_walk($directories, 'combinePath', $path);
foreach ($directories as $directory)
{
getDirectories($directory, $tree);
}
return $tree;
}
$path = 'c:/inetpub/wwwroot/someserver';
$testPath = 'c:/inetpub/wwwroot/someserver/css';
$directories = getDirectories($path);
$level = 0;
if (in_array($testPath, $directories))
{
$testPath = substr($testPath, strlen($path));
$level = strlen($testPath) - strlen(str_replace('/', '', $testPath));
}
echo '<pre>' . $level . '</pre>';
?>
you may now turn this to shit at will. :)
[Back to original message]
|