Php file search program sharing

Source: Internet
Author: User
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

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

For local systems, we can use the search provided by windows for search. However, for online systems, such as searching for files in the ftp space, this program is very useful.

PHP file finder source code:

File search for php) <? Php/** Note: Case Sensitive ** by: */if (! Empty ($ _ POST ['path']) &! Empty ($ _ POST ['key']) {echo "in path ". $ _ POST ['path']. "/In Search ". $ _ POST ['key']. 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
";}?>

The above is the PHP file finder program. You can search for local files for easy operations. I hope it will be helpful for your learning.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.