[thelist] PHP: is_dir() problem

joe stowaway at uklinux.net
Sun Sep 28 05:24:22 CDT 2003


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:

<code>

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;

   }

</code>

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

Joe




More information about the thelist mailing list