searching with a directory and subdirectories
Posted: Thu Mar 25, 2004 3:11 pm
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
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