title: Search specific file by name in a directory
body: <p>I am creating a function for search only files inside directories and inside the folder if there is, using the recursive method. I need to list the all the files matching to my keyword. I list the all the files inside the directory and trying to match the filename to my search key, that's how I am thinking to search file, I don't know it is the correct way, even though i can list the files but the search part not working,</p>
  
  <pre><code>if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        $key = trim($_POST['search']);
        $path = BOOKROOT;
  
        if (isset($key)) {
            $books = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
            $data = array();
  
            foreach ($books as $book) {
                if ($book-&gt;isDir()) {
                    continue;
                }
  
                if ($key == $book-&gt;getFilename()) {
                    $data[] = $book-&gt;getFilename();
                }
            }
              // Load view
              $this-&gt;view('books/searchpdf', $data);
        }
  }
  </code></pre>