php 目录管理,[PHP文件管理器]①--遍历目录
遍歷目錄
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
)
)
總結
以上是生活随笔為你收集整理的php 目录管理,[PHP文件管理器]①--遍历目录的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php redis 源码分析,从源码中分
- 下一篇: php 匹配正则,php正则匹配类