Hello.
I'm trying to find some solutions for my issue.

I wanted to made an local or external webpage on the webserver which is in fact file server, with the simple php web page with the search bar with the input, field and that page needs to output the search results in the text form or in any other form. I mean the goal is to get searched files or folders and where is their location.

I had couple of ideas, but I cant workaround any of them successfully, I would like to list all of my ideas and I would like that some of the pro users would tell me did they stumble across the similar codes or solutions or even complete projects or eventually the tools or application which have what I need.
The platform is the file server on ubuntu server or debian server or freebsd server


The best and easiest way would be if there is some php coding and connections toward Linux commands like "locate", slocate" or "rlocate", because those commands were connected to the indexed db of files and folders already, the best way would be with the rlocate because its in the fact the real-time, because of the kernel traps.
How could I make a php code, that would connect to the command like rlocate or locate,
I'm not sure how much secure would be to connect php with rlocate or is it even possible at all. I mean its important that system security is not compromised because the web server could have access to such system command as locate.

I've searched trough 7-8 pro php books and I cant find any connection to locate or slocate or rlocate with php. Are there any?


This is the first way, the second way would be to use some loadless "file and folder indexer", which could collect the folders structure to some database, and than the web server would connect to that db. I mean there would be an external web page with the search bar and output would be in textual form or in any shape I dont care, its important that I get advanced file and folder searcher which will produce at least load on the server.

Some people said to me that they know that there are some complete project but they cant remeber the names of those projects and tools.


The third and the worst way would be if I would use SPL file and folder handling within newest versions of PHP 5.3 and above
I mean its the worst solution which would make enormous load , and it would need a lot of time to search folder structure of 500.000 files in the mass number of folders and subfolders.

Here is rough code that I had in mind:

Code:
<?php
if(isset($_POST['Editbox1']))
{
   $search_dir = "/home/incoming";
   $search = $_POST['Editbox1'];
   $found_files = array();

   $it = new FilesystemIterator($search_dir);
   foreach ($it as $file)
   {
      if(substr_count(($file_name = $file->getFilename()), $search))
        $found_files[] =  $file_name;
   }
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Untitled Page</title>
<script type="text/javascript">
<!--
function FindObject(id, doc)
{
   var child, elem;
   if(!doc)
      doc=document;
   if(doc.getElementById)
      elem=doc.getElementById(id);
   else
   if(doc.layers)
      child=doc.layers;
   else
   if(doc.all)
      elem=doc.all[id];
   if(elem)
      return elem;
   if(doc.id==id || doc.name==id)
      return doc;
   if(doc.childNodes)
      child=doc.childNodes;
   if(child)
   {
      for(var i=0; i<child.length; i++)
      {
         elem=FindObject(id,child[i]);
         if(elem)
            return elem;
      }
   }
   var frm=doc.forms;
   if(frm)
   {
      for(var i=0; i<frm.length; i++)
      {
         var elems=frm[i].elements;
         for(var j=0; j<elems.length; j++)
         {
            elem=FindObject(id,elems[i]);
            if(elem) return elem;
         }
      }
   }
   return null;
}
// -->
</script>
<script language="JavaScript" type="text/javascript">
<!--
function ShowObject(id, flag)
{
   var elem=FindObject(id);
   if(elem)
      elem.style.visibility=flag?'visible':'hidden';
}
//-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div id="wb_Image1" style="overflow:hidden;position:absolute;left:0px;top:131px;z-index:0" align="left">
&nbsp;</div>
<img src="images/201_1.jpg" id="Image1" alt="" align="top" border="0" style="width:1294px;height:405px;">
<form method="post">
   <input type="text" id="Editbox1" style="position:absolute;left:384;top:312;width:409px;font-family:Courier New;font-size:16px;z-index:1" name="Editbox1" value="<?php echo isset($_POST['Editbox1']) ? $_POST['Editbox1'] : '' ?>" title="Search 201">
   <input type="submit" id="Button1" name="Button1" value="Search" style="position:absolute;left:794;top:312;width:84px;height:27px;background-color:#FFFFE0;font-family:Arial;font-size:13px;z-index:3">
</form>
<div id="response">
  <?php
    if(isset($found_files))
    foreach($found_files as $found_file)
    {
       echo $found_file.'<br />';
    }
  ?>
</div>
</body>
</html>
The question is could you post what you know about the fastest and the best way to do this matter.

Thanks in advance.