tags:

views:

79

answers:

2

hello,

tryin to read dir content with readdir($myDirectory), but i getting error:

readdir(): supplied argument is not a valid Directory resource 

i checked with is_dir($myDirectory) is it directory or not, and yes, it is directory.

so, why i can not read dir? is it permissions problem?

just to mention, it's all on win xp box, not linux.

tnx in adv for your help!

+1  A: 

readdir expects a resource that was returned by opendir, for example:

$handle = opendir($myDirectory);
if ($handle) {
    while (($file = readdir($handle)) !== false) {
        echo $file, '<br>';
    }
}

Take also a look at the examples on the corresponding manual pages of these functions.

Gumbo
+3  A: 

is_dir() needs a path. readdir() needs a resource. The resource needed by readdir() is retrieved thanks to the opendir() method.

dir_handle (the parameter)

The directory handle resource previously opened with opendir(). If the directory handle is not specified, the last link opened by opendir() is assumed.

For example :

<?php
if ($handle = opendir('.')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            echo "$file\n";
        }
    }
    closedir($handle);
}
?>

Resources :

Colin Hebert