PHP obtains the folder list and file list.
PHP obtains the folder list and file list.
-
- /**
- * Goofy 2011-11-30
- * GetDir () is used to go to the folder list, and getFile () is used to go to the file list under the corresponding folder. The difference between the two is to determine whether there are files with the "." suffix, and the others are the same.
- */
- // Obtain the file directory list. this method returns an array.
- Function getDir ($ dir ){
- $ DirArray [] = NULL;
- If (false! = ($ Handle = opendir ($ dir ))){
- $ I = 0;
- While (false! ==( $ File = readdir ($ handle ))){
- // Remove "". "," .. ", and files with the suffix". xxx"
- If ($ file! = "." & $ File! = ".."&&! Strpos ($ file ,".")){
- $ DirArray [$ I] = $ file;
- $ I ++;
- }
- }
- // Close the handle
- Closedir ($ handle );
- }
- Return $ dirArray;
- }
- // Obtain the file list
- Function getFile ($ dir ){
- $ FileArray [] = NULL;
- If (false! = ($ Handle = opendir ($ dir ))){
- $ I = 0;
- While (false! ==( $ File = readdir ($ handle ))){
- // Remove "". "," .. ", and files with the suffix". xxx"
- If ($ file! = "." & $ File! = ".." & Strpos ($ file ,".")){
- $ FileArray [$ I] = "./imageroot/current/". $ file;
- If ($ I == 100 ){
- Break;
- }
- $ I ++;
- }
- }
- // Close the handle
- Closedir ($ handle );
- }
- Return $ fileArray;
- }
- // Call the getDir ("./dir ")......
- ?>
|