Home  >  Article  >  Backend Development  >  PHP implements a remote file finder for searching files by file name_PHP tutorial

PHP implements a remote file finder for searching files by file name_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:29:58890browse

For local, we can use the search that comes with Windows to search, but for online, such as searching for files in ftp space, this program is very useful.

Usage effect:

PHP implements a remote file finder for searching files by file name_PHP tutorial

php file finder source code:

Copy code The code is as follows:



php version file search (file search)



File search (Note: case sensitive)


Path:


Search :






/*
* Note: Case sensitive
* by: http://www.jb51.net
*/
if(!empty($_POST['path'])&&!empty($_POST['key'])){
echo "Search for ".$_POST['key']." in the path ".$_POST['path']."/ 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 " < ;b> $dirName
n";
$GLOBALS['r_dir_num']++;
}
}
}else {
die("There is no such path! ");
}
}

delDirAndFile($_POST['path']);
echo "


This time a total of ".$file_num." files and folders ".$dir_num." were found< br/>";
echo "
A total of ".$r_file_num." files and folders ".$r_dir_num." matching the results
";
}

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/768135.htmlTechArticleFor local, we can use the search that comes with windows to search, but for online, such as searching for ftp For files in the space, this program is very useful. Usage effect: php text...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn