Search engine to search files in folders

Hey guys,

Today we will go through a simple algorithm to search files in a folder.

Lets search in a different way..kinda like if we are searching for a image we will mention image name and click on image radio button and then search. Similary docs,audios,videos,other files etc etc.

Hope our simple mission is clear..lets see how..dont panic folks..its pretty simple function which satisfies our requirement clearly. The function is glob() which has been introduced in PHP4.

First design a simple template with textbox to search and radio buttons for selecting options. I hope changing css is not a big thing once we are done with functionality then we can process into it.

filesearch.php:

<form id=”form1″ name=”form1″ method=”post” action=”searchresult.php”>
<label>Search
<input type=”text” name=”stringsearch” />
<br />
<br />
<input name=”radiobutton” type=”radio” value=”image” />
Images
<input name=”radiobutton” type=”radio” value=”doc” />
doc/docx
<input name=”radiobutton” type=”radio” value=”ppt” />
ppt/pptx
<input name=”radiobutton” type=”radio” value=”xls” />
xls/xlsx
<input name=”radiobutton” type=”radio” value=”audio” />
audio
<input name=”radiobutton” type=”radio” value=”video” />
video
<input name=”radiobutton” type=”radio” value=”others” />
others<br />
<br />
</label>
<label>
<input type=”submit” name=”Submit” value=”Submit” />
</label>
</form>

07-02-2014 09-56-32

searchresult.php:

<?php
$dir=”C:\wamp\www\apps”;

$strsear=$_POST[“stringsearch”];
$radio=$_POST[“radiobutton”];
switch ($radio)
{
case “image”:
$result=$strsear.”*.jpg”;

break;
case “doc”:
//similarly doc
break;
case “ppt”:
//similarly ppt
break;
case “xls”:
//similarly xls
break;
case “audio”:
//similarly audio
break;
case “video”:
//similarly video
break;
default:
$result=$strsear.”*.php”; //list anyother files
}
foreach(glob($dir.DIRECTORY_SEPARATOR.$result) as $filename){

echo $filename.”<br/>”;
}
?>

This is a simple prototype to achieve only for a simple search of a filename in folders. In my next post i will share how to search files in folders and subfolders clearly. Hope you like it 🙂

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s