PHP gets all the files in the specified directory (including subdirectories),
PHP gets all files (including subdirectories) in the specified directory
Test environment under Linux, if you want to be in Windows, correct the way that directory paths are found in $new_dir
php function Get_file_list ($dir) {$file _list=Array (); $file _dir_list=Array (); $dir _list= Scandir ($dir);//Find a directory foreach($dir _list as$r) { if($r = ='.'|| $r = ='..') { Continue; } $new _dir= $dir.'/'. $r; if(Is_dir ($new _dir)) {$file _dir=get_file_list ($new _dir); $file _dir_list=Array_merge ($file _dir_list, $file _dir); } Else{$file _list[]=$new _dir; } } returnArray_merge ($file _list, $file _dir_list);} $file _list= Get_file_list ('.');p Rint_r ($file _list);
Scandir Definition and usage
The Scandir () function returns an array that contains the files and directories in the specified path.
If successful, returns an array, or false if it fails. If directory is not a directory, returns a Boolean value of false and generates an e_warning-level error.
Grammar
Scandir (Directory,sort,context)
Parameters |
Description |
Directory |
Necessary. Specifies the directory to scan. |
Sort |
Optional. Specify the order of arrangement. The default is 0 (ascending). If 1, it is descending. |
Context |
Optional. The environment that specifies the directory handle. Context is a set of options that modify the behavior of a directory stream. |
Example
Phpprint_r (Scandir ("images"));
Output:
Array ([0] = = . [ 1] = =. [2] = = dog.jpg[3] = house.jpg[4] = logo.gif)
http://www.bkjia.com/PHPjc/1106269.html www.bkjia.com true http://www.bkjia.com/PHPjc/1106269.html techarticle php gets all the files in the specified directory (including subdirectories), PHP gets all the files under the specified directory (including subdirectories) under Linux, if you want in Windows, please correct $n ...