Click to See Complete Forum and Search --> : is_dir() probLem, HeLp please


fireblade
12-27-2007, 01:29 AM
Hi folks

I'm having a bit of trouble with is_dir() in PHP 4.1.2. I want to
create a menu dynamically from the names of folders in a web directory,
and I'm using this code to create an array of the folders:

function getDirContents($whichdir)
{

// directories to ignore
$exclusions[] = ".";
$exclusions[] = "..";
$exclusions[] = "includes";
$exclusions[] = "images";

$handle = opendir($whichdir);
while($dir = readdir($handle))
{
if ((is_dir($dir)) && (!(in_array($dir, $exclusions))))
{
$myDirList[] = $dir;
}
}
closedir($handle);
return $myDirList;

}


It works just fine if the function is called from a script where
$whichdir is the current working directory or a sub-directory in the
script's path, but not when $whichdir is 'up' a directory. I've tried
using relative and absolute paths.

The error is a peculiar one - the opendir() and readdir() seem to work,
but the array returned is empty. If I exclude the is_dir() check, I get
a full list of directories and files.

I've RTFM and can't find anything about is_dir() behaviour when
operating on a higher-level directory.

Anyone run into this one?

Thanks in advance

scragar
12-27-2007, 08:25 AM
is_dir($whichdir.$dir)
or
is_dir($whichdir.'/'.$dir)
depending on if you have the / on the end of the dir names.