PHP file lookup program. After a path is entered, all the files and folders under the directory will be traversed, and each file under the folder can be found recursively, and then matched with the entered keyword through the file name, you can find the files you want. For local files, we can use the windows Search. However, for online files, such as files in the ftp space, this program is very useful.
Effect:
PHP file finder source code:
The Code is as follows:
File search for php)
/*
* Note: Case Sensitive
* By: http://www.php.net
*/
If (! Empty ($ _ POST ['path']) &! Empty ($ _ POST ['key']) {
Echo "in the path". $ _ POST ['path']. "/, find". $ _ POST ['key']. "And the result is:
";
$ File_num = $ dir_num = 0;
$ R_file_num = $ r_dir_num = 0;
$ FindFile = $ _ POST ['key'];
Function delDirAndFile ($ dirName ){
If ($ handle = @ opendir ("$ dirName ")){
While (false! ==( $ Item = readdir ($ handle ))){
If ($ item! = "." & $ Item! = ".."){
If (is_dir ("$ dirName/$ item ")){
DelDirAndFile ("$ dirName/$ item ");
} Else {
$ GLOBALS ['file _ num'] ++;
If (strstr ($ item, $ GLOBALS ['findfile']) {
Echo"
$ DirName/$ item
\ N ";
$ GLOBALS ['r _ file_num '] ++;
}
}
}
}
Closedir ($ handle );
$ GLOBALS ['dir _ num'] ++;
If (strstr ($ dirName, $ GLOBALS ['findfile']) {
$ Loop = explode ($ GLOBALS ['findfile'], $ dirName );
$ CountArr = count ($ loop)-1;
If (empty ($ loop [$ countArr]) {
Echo"
$ DirName
\ N ";
$ GLOBALS ['r _ dir_num '] ++;
}
}
} Else {
Die ("this path is not available! ");
}
}
DelDirAndFile ($ _ POST ['path']);
Echo"
". $ File_num." files, Folders ". $ dir_num." are found in this query.
";
Echo" A total of ". $ r_file_num." files and folders ". $ r_dir_num." matching results
";
}
?>