title: Regex MongoDB PHP Query
body: <p>I'm looking to perform a REGEX on a MongoDB find query that only finds anything with image in the string, what its searching is a filetype header so it would generally looked like image/png or text/html.</p>
  
  <p>I am running this code for the regex:</p>
  
  <pre><code>array('fileType'=&gt;array('$regex'=&gt;'^image'))
  </code></pre>
  
  <p>And this code alltogether:</p>
  
  <pre><code>foreach ($this-&gt;grid-&gt;find(array('fileType'=&gt;array('$regex'=&gt;'^image'))) as $file) {
                          $id = (string) $file-&gt;file['_id'];
                          $filename = htmlspecialchars($file-&gt;file["filename"]);
                          $filetype = isset($file-&gt;file["filetype"]) ? $file-&gt;file["filetype"] : 'application/octet-stream';
  
                          if($filetype == 'image/'.$chosenfile.''){
                              $links[] = sprintf('&lt;img src="lib/download.php?id=%s" height="200px" width="200px"&gt;', $id);
                          }elseif($chosenfile == ''){
                               $links[] = sprintf('&lt;img src="lib/download.php?id=%s" height="200px" width="200px"&gt;', $id);
                          }
                      }
  </code></pre>