I need to create a search engine to search PHP pages with a main directory and its subdirectories for a keyword which is obtained as input from the user. It needs to return the pages in which the keyword is located.
I have written a script but for some reason its doesnt seem to work and gives me the following error
- fopen(rfp/rfpmain.php): failed to open stream: Permission denied in file name
- filesize(): Stat failed for rfp/rfpmain.php (errno=13 - Permission denied)
- fread(): supplied argument is not a valid stream resource
- fclose(): supplied argument is not a valid stream resource
- stristr(): Empty delimiter
The code is as under :
<?
$find = "$string";
$directory = "rfp";
$d = dir($directory);
while(($file = $d->read())!==false)
{
if($file!="." && $file!=".." && stristr($file, ".php")!==false)
{
$open = fopen($directory."/".$file, "rb");
$read = fread($open, filesize($directory."/".$file));
fclose($open);
clearstatcache();
if(stristr($read, $find)!==false)
{
$matches[] = $directory."/".$file;
}
}
}
echo "<b>".count($matches)."</b> matches have been found.<hr>";
if(count($matches)>0)
{
foreach($matches as $path)
{
echo "File Match : <a href=\"{$path}\">{$path}</a><br>";
}
}
?>
Can someone please help me. thanks
searching with a directory and subdirectories
Moderator: General Moderators
"Permission denied" was the first error: the others are just results of that.
Is the script file readable as user "nobody"?
Is the directory "rfp" readable and executable by user "nobody"?
You might also want to change this line:
To something more like:
Is the script file readable as user "nobody"?
Is the directory "rfp" readable and executable by user "nobody"?
You might also want to change this line:
Code: Select all
$open = fopen($directory."/".$file, "rb");Code: Select all
if (($open = @fopen($directory."/".$file, "rb"))===false) {
print("Couldn't open $file<br>\n");
continue;
}Re: searching with a directory and subdirectories
You might want to try the search engine I developed. Its called 'The Search Engine Project'. Its in http://www.hotscripts.com/Detailed/33759.html. I will be glad to help on the script.sulen wrote:I need to create a search engine to search PHP pages with a main directory and its subdirectories for a keyword which is obtained as input from the user. It needs to return the pages in which the keyword is located.
Thanks
Girish R