开发者

Is there a glitch with opendir/readdir?

Here is my PHP code:

<?php

// Enumerate the directories in styles
$styles_dir = 'styles/';

if($handle = opendir($styles_dir))
{
    while(FALSE !== ($file = readdir($han开发者_如何学Pythondle)))
    {
        echo $file . '(' . is_dir($file) . ')<br>';
    }
}
?>

Here are the directories in styles:

http://files.quickmediasolutions.com/php.jpg

And here is the output:

.(1)
..(1)
forest()
industrial()

Why aren't forest and industrial directories?


The path for is_dir is relative to the base file, so you really need to do a test like

is_dir($styles_dir . '/' . $file)

Note that this is masked for the . and .. "directories" as these exist everywhere.


You need to prefix the directory name to the file name as is_dir works relative to the current directory.

Change

echo $file . '(' . is_dir($file) . ')<br>';

to

echo $file . '(' . is_dir("$styles_dir/$file") . ')<br>';

Alternatively you can change the directory to $styles_dir using chdir and then your current code will work.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜