遍历目录
1.得到需要管理目录中的内容
2.通过遍历目录来实现
Paste_Image.png
dir.func.php
function readDirectory($path) {
$handle = opendir ( $path );
// !== 防止文件名为0 被忽略
while ( ($item = readdir ( $handle )) !== false ) {
if ($item != "." && $item != "..") {
if (is_file ( $path . "/" . $item )) {
$arr ['file'] [] = $item;
}
if (is_dir ( $path . "/" . $item )) {
$arr ['dir'] [] = $item;
}
}
}
closedir ( $handle );
return $arr;
}
$path = "file";
print_r ( readDirectory ( $path ) );
?>
Array
(
[file] => Array
(
[0] => 2.jpg
[1] => file.func.php
[2] => imooc.txt
[3] => imoocnew_3424a2ff04.txt
[4] => imoocnew_91e0f5ffbe.txt
[5] => imooc_php.txt
[6] => test.html
[7] => test123.txt
)
[dir] => Array
(
[0] => abc
[1] => imooc1
)
)