Page 1 of 1

searching with a directory and subdirectories

Posted: Thu Mar 25, 2004 3:11 pm
by sulen
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

Posted: Thu Mar 25, 2004 6:11 pm
by Farrier
"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:

Code: Select all

$open = fopen($directory."/".$file, "rb");
To something more like:

Code: Select all

if (($open = @fopen($directory."/".$file, "rb"))===false) {
    print("Couldn't open $file<br>\n");
    continue;
}

Posted: Thu Mar 25, 2004 8:53 pm
by aleigh
Try running:

<?php
echo get_current_user();
?>

It will output the user your script is executing on, and you might become enlightened if this is not what you expect.

Re: searching with a directory and subdirectories

Posted: Thu May 20, 2004 12:03 am
by GirishR
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.
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.

Thanks
Girish R