获得文件和文件夹的函数

<?php
function getDir($dir) {
$dirArray[]=NULL;
if (false != ($handle = opendir ( $dir ))) {
$i=0;
while ( false !== ($file = readdir ( $handle )) ) {
//去掉"“.”、“..”以及带“.xxx”后缀的文件
if ($file != "." && $file != ".."&&!strpos($file,".")) {
$dirArray[$i]=$file;
$i++;
}
}
//关闭句柄
closedir ( $handle );
}
return $dirArray;
}
function getFile($dir) {
$fileArray[]=NULL;
if (false != ($handle = opendir ( $dir ))) {
$i=0;
while ( false !== ($file = readdir ( $handle )) ) {
//去掉"“.”、“..”以及带“.xxx”后缀的文件
if ($file != "." && $file != ".."&&strpos($file,".")) {
$fileArray[$i]="./imageroot/current/".$file;
if($i==100){
break;
}
$i++;
}
}
//关闭句柄
closedir ( $handle );
}
return $fileArray;
}
var_dump(getDir("../"));
var_dump(getFile("../"));
?>

posted on   liuwenbohhh  阅读(180)  评论(0)    收藏  举报

< 2025年4月 >
30 31 1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 1 2 3
4 5 6 7 8 9 10

统计

点击右上角即可分享
微信分享提示