开发者

is_dir doesn't recognize directories. Why?

开发者 https://www.devze.com 2022-12-27 03:43 出处:网络
I have this function: if (is_dir($dir)) { //are we able to open it? if ($dh = opendir($dir)) { //Let\'s cycle

I have this function:

if (is_dir($dir)) {
        //are we able to open it?
        if ($dh = opendir($dir)) {
            //Let's cycle
  开发者_如何学C          while (($subdir = readdir($dh)) !== false) {
                if ($subdir != "." && $subdir != "..") {

                    echo $subdir;

                }
        }
}

This returns:

directory1 , directory2, directory3 etc.. etc..

Hoever if I do this:

    if (is_dir($dir)) {
        //are we able to open it?
        if ($dh = opendir($dir)) {
            //Let's cycle
            while (($subdir = readdir($dh)) !== false) {
                if ($subdir != "." && $subdir != "..") {

                    if (is_dir($subdir)) { 
                       echo $subdir;
                    }

                }
        }
}

It doesn't print nothing!

Why does this happens? I'm running the script withing windows and XAMPP for testing purposes. The directory does in fact contain directories.

Thank you


is_dir($dir . '/' . $subdir)


readdir() only gives the file/dir name and not the full path (which is_dir apparently needs).

Found here - http://www.php.net/manual/en/function.is-dir.php#79622


Its because $dir is a full path where as $subdir is only a path fragment

0

精彩评论

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