像在文件资源管理器中一样获取文件夹和文件



我对php中的所有文件系统功能(glob,scandir,opendir...(感到困惑。
我只需要一个文件夹和文件的列表 - 就像在文件资源管理器中一样
像这样:

$path = 'home';
$arr = content of $path;
foreach($arr as $el){
if($el is a folder){echo "<div class='folder'>$el</div>";}
elseif($el is a file){echo "<div class='file'>$el</div>";}
}

有什么帮助吗?

一种方法:

$path = 'home'; // setting path
# Find pathnames matching a pattern 
# pattern : "home/*"
# will match : home/dir1, home/file.jpg, etc.
# and it will return an array
$arr = glob($path."/*");
foreach($arr as $el){
if ( is_dir($el) ) {
echo "<div class='folder'>" . basename($el) . "</div>";
} else {
echo "<div class='file'>" . basename($el) . "</div>";
}
}

相关内容

最新更新