0

I was actually able to find a post by another user here which lead me in the right direction. I haven't bookmarked it but i will as soon as i have a bit of time. Meanwhile, here is the solution to my problem:

<form name="search-form" onclick="this.form.submit()" id="search-form" method="post">
<input size="30" name="search" type="text" id="search" />
<input class="button" type="submit" name="stylesearch" value="search" />
</form>
<?php
    if(isset($_POST['stylesearch']))
    {
    $search = $_POST['search'];
    if (@get_magic_quotes_gpc())
        {
        $search = stripslashes($search);
        }
    $it = new RecursiveDirectoryIterator("galleries");
    $allowed=array("jpg");
    foreach(new RecursiveIteratorIterator($it) as $file) {
        if (false !== stripos($file, $search))
    {
    echo 'You have searched for the following '.$it.' style(s): <a href="'. $file . '" target="">'.str_replace(array(' - ','.jpg'), array(' '), $search).'</a>' . "<br>";
        }
    }
echo " ";
}
else
{
echo "<p>search a style</p>";
}
?>

Here is the problem:

I have a "gallery/" folder which contains multiple sub-folders that go a few levels deep. I have successfully made inventory of all jpgs contained in all subfolders, in a nice list with direct links to the pictures. That's the easy part.

What i'd like to do is to have an input box where i can type a term, and upon clicking Submit, only the files that contain that term in the file name will show up in the list.

I have created the input button, and when you click it it shows the entire list (meaning it simply runs the code as it is supposed to run). For the life of me, i can't understand how to make it work in a way that it will show only the files matching what i type in the $search field.

Is what i am trying to do even possible?

Here is the code:

<form action="searchlist.php" method="post"><input name="searchstyle" id="searchstyle" type="search" value=""><button

name="stylesearch" id="stylesearch">style search
'.str_replace(array(' - ','.jpg'), array(' '), $file).'' . "
"; } else{ $dirs[]=$dest; } } } } return $files; } printAll(getcwd()); } ?>

  • You find example code and more in related questions. For example here: [RecursiveFilterIterator re-instantiated within RecursiveIteratorIterator?](http://stackoverflow.com/q/16712253/367456) – hakre May 26 '13 at 17:57
  • Uh, I'm guessing by the question, SPL is a little difficult – Farkie May 26 '13 at 18:00
  • Thanks, i don't really know much about regular expressions, so the related link about RecursiveIteratorIterator didn't help much at all, as what i need is a way to type a term into the search field so that only the file names that contain the terms typed will display in the list. – fabiobasile May 26 '13 at 21:46

0 Answers0