This code comes from the php Tutorial cms and feels very good, so I will share it with you. If you need it, please refer to it.
/**
* File scanning
* @ Param $ filepath Directory
* @ Param $ whether to search for sub-directories
* @ Param $ ex search extension
* @ Param $ whether isdir only searches for directories
* @ Param $ whether md5 verification code is generated
* @ Param $ enforcement force update cache
*/
Function scan_file_lists ($ filepath, $ subdir = 1, $ ex = '', $ isdir = 0, $ md5 = 0, $ enforcement = 0 ){
Static $ file_list = array ();
If ($ enforcement) $ file_list = array ();
$ Flags = $ isdir? GLOB_ONLYDIR: 0;
$ List = glob ($ filepath .'*'.(! Empty ($ ex) & empty ($ subdir )? '.'. $ Ex: ''), $ flags );
If (! Empty ($ ex) $ ex_num = strlen ($ ex );
Foreach ($ list as $ k => $ v ){
$ V1 = str_replace (PHPCMS_PATH, '', $ v );
If ($ subdir & is_dir ($ v )){
Scan_file_lists ($ v. DIRECTORY_SEPARATOR, $ subdir, $ ex, $ isdir, $ md5 );
Continue;
}
If (! Empty ($ ex) & strtolower (substr ($ v,-$ ex_num, $ ex_num) ==$ ex ){
If ($ md5 ){
$ File_list [$ v1] = md5_file ($ v );
} Else {
$ File_list [] = $ v1;
}
Continue;
} Elseif (! Empty ($ ex) & strtolower (substr ($ v,-$ ex_num, $ ex_num ))! = $ Ex ){
Unset ($ list [$ k]);
Continue;
}
}
Return $ file_list;
}