开发者

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

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!


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 :

  • php.net - readdir()
  • php.net - is_dir()
  • php.net - opendir()


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜