lhm166
/**
 * getDir()取文件夹列表,getFile()取对应文件夹下面的文件列表,二者的区别在于判断有没有“.”后缀的文件,其他都一样
 */
 
//获取文件目录列表,该方法返回数组
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;
}
 
//调用方法getDir("./dir")……
?> 

 

分类:

技术点:

相关文章:

  • 2021-09-11
  • 2021-09-11
  • 2021-10-17
  • 2019-06-27
  • 2021-09-11
  • 2021-11-22
  • 2021-11-04
  • 2021-10-14
猜你喜欢
  • 2021-09-11
  • 2021-12-16
  • 2021-09-11
  • 2021-09-11
  • 2021-10-16
  • 2021-08-31
  • 2021-12-15
相关资源
相似解决方案