/** * GETDIR () Take the Folder List, GetFile () take the corresponding folder below the file list, the difference between the two is to determine whether there is "." Suffix file, the others are the same*/ //Gets the file directory list, which returns the arrayfunctionGetdir ($dir) { $dirArray[]=NULL; if(false!= ($handle=Opendir($dir ))) { $i=0; while(false!== ($file=Readdir($handle )) ) { //Remove the ".", ".." and files with a ". xxx" suffix if($file! = "." &&$file!= ".." &&!Strpos($file,".")) { $dirArray[$i]=$file; $i++; } } //Close Handle Closedir($handle ); } return $dirArray;} //get a list of filesfunctionGetFile ($dir) { $fileArray[]=NULL; if(false!= ($handle=Opendir($dir ))) { $i=0; while(false!== ($file=Readdir($handle )) ) { //Remove the ".", ".." and files with a ". xxx" suffix if($file! = "." &&$file!= ".." &&Strpos($file,".")) { $fileArray[$i]= "./imageroot/current/".$file; if($i==100){ Break; } $i++; } } //Close Handle Closedir($handle ); } return $fileArray;} //Call Method Getdir ("./dir") ...?>
PHP read file list of folders