I'm trying to find out why this entire code below is producing only ONE result after running all of the functions, instead of producing multiple results.
The code is supposed to take a single result from a text-based search, and then check each file on the user's server and find that string, then output each file that contains that search string.
The code is producing only one result, instead of outputting all of the files that would contain the entered string.
I had this working at one time, but the code was modified from a prior question on this website, and now is not working exactly correct.
<?php
if (!isset($_REQUEST['query']))
{
//Ask for query here :)
//echo "<p style=\"color:darkgray; font-family:arial\">Sorry. Please enter a search term.</p>";
exit;
}
$query = isset($_REQUEST['query']) ? $_REQUEST['query'] : '';
if (empty($query))
{
echo "<p style=\"color:#575757; font-family:arial\">We are unable to process your request becuase you didn't enter a search term. Please try again.</p>";
exit;
}
$filesFound = find_files('.');
if (!$filesFound)
{
echo "<p style=\"color:#575757; font-family:arial\">No files contained the search, \"$query\". Please try another search.</p>";
}
function find_files($seed)
{
if (!is_dir($seed)) return false;
$found = false;
$dirs = array($seed);
while (NULL !== ($dir = array_pop($dirs)))
{
if ($dh = opendir($dir))
{
while (false !== ($file = readdir($dh)))
{
if ($file == '.' || $file == '..') continue;
$path = $dir . '/' . $file;
if (is_dir($path))
{
$dirs[] = $path;
}
else
{
if (preg_match('/^.*\.(php[\d]?|js|txt)$/i', $path))
{
if (!$found)
{
$found = check_files($path);
}
}
}
}
closedir($dh);
}
}
return $found;
}
function check_files($this_file)
{
$query = $_REQUEST['query'];
$str_to_find = $query;
if (($content = file_get_contents($this_file)) === false)
{
echo("<p style=\"color:#575757; font-family:arial\">Could not check $this_file</p>
");
return false;
}
else
{
if (stristr($content, $str_to_find))
{
echo("<p style=\"color:#575757; font-family:arial\">$this_file -> contains $str_to_find</p>
");
return true;
}
}
}
?>