readdir()

diabolo

Community Advocate
Community Support
Messages
1,682
Reaction score
32
Points
48
How come this code does not work?

PHP:
   $path = ROOT.'gallery/events';
   $dir_handle = @opendir($path) or die("Unable to open $path");
   $count = "0";
   while ($file = readdir($dir_handle)) {
      if ($file!="." && $file!=".." && is_dir($file)) {
         $galleryDirectory[$count] = $file;
         $count++;
      }
   }
   closedir($dir_handle);

it messes up when I add the "&& is_dir($path)" part, other than that it works fine
 

Twinkie

Banned
Messages
1,389
Reaction score
12
Points
0
I believe because the $file variable contains the name of the directory, and not the full path. So this is a revision that should work:

PHP:
   $path = ROOT.'gallery/events/';
   $dir_handle = @opendir($path) or die("Unable to open $path");
   $count = "0";
   while ($file = readdir($dir_handle)) {
      if ($file != "." && $file != ".." && is_dir($path.$file)) {
         $galleryDirectory[$count] = $file;
         $count++;
      }
   }
   closedir($dir_handle);
 
Last edited:

diabolo

Community Advocate
Community Support
Messages
1,682
Reaction score
32
Points
48
thanks, i wouldn't have picked that up by myself
 
Top