SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    nyc
    Posts
    223
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    readdir warning: not a valid directory ressource?...

    What could be the reason for this:
    I have:
    PHP Code:
    if ($handle opendir('folder/sub_folder/sub_sub_folder/')) {
            while (
    false !== ($dir readdir($handle))) { 
                            
    $do_something();
                  }

    I get the waring:
    Warning: readdir(): 4 is not a valid Directory resource in...

    Why?... I don't understand why 'folder/sub_folder/sub_sub_folder/' is not a valid directory ressource, and where is that '4' coming from in the warning message??....

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Either that folder does not exist or you do not have read permission to it. Try using a full path to the folder (e.g. /var/www/html/folder/sub_folder etc.)

  3. #3
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    nyc
    Posts
    223
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the folder exists, the path is a relative path to the page containing the script, and it is right.
    I have read and write permission on the folder and all its contents.
    Here's the entire script, and I still get an error message (see bellow):


    PHP Code:
    <?php
    ini_set 
    ('display_errors',1);
    error_reporting (E_ALL & ~E_NOTICE);
    ?>
    <html>
    <body>
    <?php
    if ($handle opendir("pages/")) {
        while (
    false !== ($dir readdir($handle))) { 
            if (
    is_dir($dir)) {
                
    $folders[]=$dir;
            }
            
    closedir($handle);
            if (
    count($folders)) {
                foreach (
    $folders as $fold) {
                    echo 
    '<div><a href="#">'.$fold.'</a></div>';
                }
            }
        }
    }
    ?>
    </body>
    </html>
    error message:
    Warning: readdir(): 2 is not a valid Directory resource in /Users/seb/Sites/httpdocs/script.php on line 5.

    Now, readdir() is on line 9, not 5. And I have no idea where that '2' comes from in the warning message.
    This is driving me crazy.

  4. #4
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    nyc
    Posts
    223
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    problem solved!

    It was a curly braces mistake, I had to replace:

    PHP Code:
    if ($handle opendir("pages/")) { 
        while (
    false !== ($dir readdir($handle))) { 
            if (
    is_dir($dir)) { 
                
    $folders[]=$dir
            } 
            
    closedir($handle); 
            if (
    count($folders)) { 
                foreach (
    $folders as $fold) { 
                    echo 
    '<div><a href="#">'.$fold.'</a></div>'
                } 
            } 
        } 

    with
    PHP Code:
    if ($handle opendir("pages/")) { 
        while (
    false !== ($dir readdir($handle))) { 
            if (
    is_dir($dir)) { 
                
    $folders[]=$dir
            }
     }
           
    closedir($handle); 
           if (
    count($folders)) { 
               foreach (
    $folders as $fold) { 
                   echo 
    '<div><a href="#">'.$fold.'</a></div>'
                 
            } 
        } 



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •