title: Search files in multiple directories using PHP
body: <p>I wrote some script a while ago, basically search a specified folder on the server and returns a list of the images in that folder. The directory was set via a variable which changed depending on which section you were searching.</p>
  
  <p>But now I need to amend this in a way in which it will search all of the directories and list the images from various directories.</p>
  
  <p>Here is the script I currently use:</p>
  
  <pre><code>&lt;?php
  $dir = "assets/folder1/subfolder1/";
  
  // Open a known directory, and proceed to read its contents
  if (is_dir($dir)) {
      if ($dh = opendir($dir)) {
          while (($file = readdir($dh)) !== false) {
              if(stristr($file,$_POST['image_search'])){
                  echo('&lt;li&gt;&lt;a href="/'.$dir . $file.'"&gt;'. $file .'&lt;/a&gt;&lt;/li&gt;'."\n");
              }
          }
          closedir($dh);
      }
  }
  ?&gt;
  </code></pre>
  
  <p>That searches assets/folder1/ no problem, but I also have (folder1/subfolder2, folder2/subfolder1, folder2/subfolder2/ etc etc)</p>
  
  <p>Thinking there must be some kind of wildcard search on directories etc, but really struggling to think around it!</p>
  
  <p>I thought something like glob could help out, but not much luck with that either</p>
  
  <pre><code>$dir = glob("/assets/*/*/");
  </code></pre>