开发者

displaying files and DIRECTORIES via php?

开发者_开发技巧i have a propably rather simple question: I'm using the following script to read a folder?

    $count = 0;
if ($handle = opendir(PATH)) {
    $retval = array();
    while (false !== ($file = readdir($handle))) {
        $ext = pathinfo($file, PATHINFO_EXTENSION);
        if ($file != '.' && $file != '..' && $file != '.DS_Store' && $file != 'Thumbs.db') {
            $retval[$count] = $file;
            $count = $count + 1;
        } else {
            //no proper file
        }
    }
    closedir($handle);
}

if a file is an image I print it as an image: print "";

However i wonder how i can display FOLDERS? If i have a subfolder inside of the folder i'm currently running through? how can i print that one?


use glob instead of scandir

$dirs = glob(PATH."/*", GLOB_ONLYDIR);
$images = glob(PATH."/*.[jJ][pJ][gG]");

foreach ($dirs as $name) echo "<b>$name</b><br>\n";
foreach ($images as $name) echo $name."<br>\n";


Use scandir instead of readdir. http://us.php.net/manual/en/function.scandir.php

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜