$dir = '/master/files'; $files = scandir($dir); foreach($files as $file){ if(($file != '.') && ($file != '..')){ if(is_dir($dir.'/'.$file)){ echo '<li class="folder">'.$file.'</li>'; }else{ echo '<li class="file">'.$file.'</li>'; } } }
从上面的脚本,我得到结果:
images (folder) index.html javascript (folder) style.css
试试这个 :
原文链接:https://www.f2er.com/php/134613.html$dir = '/master/files'; $directories = array(); $files_list = array(); $files = scandir($dir); foreach($files as $file){ if(($file != '.') && ($file != '..')){ if(is_dir($dir.'/'.$file)){ $directories[] = $file; }else{ $files_list[] = $file; } } } foreach($directories as $directory){ echo '<li class="folder">'.$directory.'</li>'; } foreach($files_list as $file_list){ echo '<li class="file">'.$file_list.'</li>'; }