如何使用 PHP 在目录中显示文件夹的限制?下面的代码显示了所有文件夹,但我只想查看 10 个文件夹。
function folderlist() {
$startdir = './';
$ignoredDirectory[] = '.';
$ignoredDirectory[] = '..';
if(is_dir($startdir)) {
if($dh = opendir($startdir)) {
while(($folder = readdir($dh)) !== false) {
if(!(array_search($folder, $ignoredDirectory) > -1)) {
if(filetype($startdir.$folder) == "dir") {
$mtime = filemtime($startdir.$folder);
$directorylist[$mtime]['name'] = $folder;
$directorylist[$mtime]['path'] = $startdir;
}
}
}
closedir($dh);
}
}
krsort($directorylist, SORT_NUMERIC);
return $directorylist;
}
$folders = folderlist();
foreach($folders as $folder) {
$path = $folder['path'];
$name = $folder['name'];
echo '<div class="urbangreymenu"><ul><li><a href="'.$path.'index.php?wallpapers='.$name.'" target="_parent">'.$name.'</a></li></ul></div>';
}