Hi, I'm new to php and need help.
I'm trying to search files on the basis of their content in which I got success.
for that I'm running a function in php as follows and showing result table.
<!--searchFileContents CLASS-->
<?php
#class for keyword Search
class searchFileContents{
#Declarations of variables
var $dir_name = '';
var $search_phrase = '';
var $allowed_file_types = array('txt', 'htm', 'html');
var $foundFiles;
var $myfiles;
#function to search the phrase with input parameters like
#directory name and the phrase to search
function search($directory, $search_phrase)
{
$this->dir_name = $directory;
$this->search_phrase = $search_phrase;
# get all the files in all the directories
$rDirIter = new RecursiveDirectoryIterator($this->dir_name, FilesystemIterator::SKIP_DOTS);
$this->myfiles = new RecursiveIteratorIterator ( $rDirIter);
#array declaration
$this->foundFiles = array();
if ( empty($this->search_phrase) ) die('Please type something to search!');
if ( empty($this->dir_name) ) die('You must select a directory to search');
#Search the keyword inside the files
foreach ( $this->myfiles as $f )
{
#in_array() will check if $allowed_file_types has the extension or not
#explode() will convert the path into array
#array_pop() will Pop the element off the end of array, here extension of file
if ( in_array(array_pop(explode ( '.', $f )), $this->allowed_file_types) )
{
$contents = file_get_contents($f);
if ( stripos($contents, $this->search_phrase) !== false )
$this->foundFiles [] = $f;
}
}
return $this->foundFiles;
}
}
?>
which I'm calling @
<?php
#Search the keyword
if($_POST['Submit']=="Submit")
{
$SearchQuery = $_POST['txt_query']; #Search keyword
$TestPath="C:/intranet/www/Documnet_Search";
$search = new searchFileContents;
$search->search($TestPath, $SearchQuery);
$narray = array();
$narray = $search->foundFiles;
Now my search is getting bigger as new files are added and now its taking time.
Could anyone please help me to implement a Progress bar to let the user know that the search in still in progress?