PHP -Search for a file on a site
Here is a script I wrote to help me find files on my php server. You enter the text to search for and it will return a list of files and directories that contain the search term.
<form action="search.php" method="get" >
<label for="searchterm">search for</label>
<input type="text" name="searchterm" id="searchterm"
value="<?php echo $_REQUEST["searchterm"]; ?>" /><br />
<label for="dir">directory path to search</label>
<input type="text" name="dir" id="dir" value="<?php echo $_REQUEST["dir"]; ?>" />
<input type="submit" value="go" />
</form>
<?php if($_REQUEST["searchterm"]){>
searchDirectory($_REQUEST["dir"],0,$_REQUEST["searchterm"]);
}

function searchDirectory( $path = '.', $level = 0, $searchterm='' ){
$ignore = array( 'cgi-bin', '.', '..' );
$dh = @opendir( $path );

while( false !== ( $file = readdir( $dh ) ) ){ // Loop through the directory
if( !in_array( $file, $ignore ) ){
if(checkFile($file,$searchterm)){
echo "$path/$file<br />";
}
if( is_dir( "$path/$file" ) ){
searchDirectory( "$path/$file", ($level+1),$searchterm);
}//if
}//if in array> }//while

closedir( $dh );

}//function

function checkFile( $file = '', $searchterm='' ){
$file = strtolower($file);
$searchterm = strtolower($searchterm);
if(strpos($file , $searchterm)){
return true;
}
return false;
}//function
?>
 

Help my beer fund

RocketTheme Joomla Templates