+ Reply to Thread
Results 1 to 3 of 3

Thread: readdir()

  1. #1
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    readdir()

    How come this code does not work?

    PHP Code:
       $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

  2. #2
    Twinkie is offline Banned Twinkie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,389

    Re: readdir()

    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 Code:
       $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 by Twinkie; 07-24-2009 at 06:29 PM.

  3. #3
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: readdir()

    thanks, i wouldn't have picked that up by myself

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers