title: How can I display all images and videos in a folder and subfolders ordered by date (newer on top)?
body: <p>Using PHP, I'm trying to display all images in a folder and subfolders, ordered by date (newer on top).</p>
  
  <p>A <a href="https://stackoverflow.com/questions/20585670/get-images-in-directory-and-subdirectory-with-glob?rq=1#_=_">script</a> from <a href="https://stackoverflow.com/users/1292052/slashingweapon">@slashingweapon</a> worked perfectly. But I just can't make it display the images ordered by date.</p>
  
  <p>I'm trying "filemtime" but can't make it work (I'm not a programmer, just a diy person).</p>
  
  <p>I'll be glad if someone could give some advice.</p>
  
  <p>Thank you!</p>
  
  <pre><code>&lt;?php
  $rdi = new RecursiveDirectoryIterator("uploads/prevImgs/");
  $it = new RecursiveIteratorIterator($rdi);
  foreach($it as $oneThing)
      if (is_file($oneThing))
          echo '&lt;img src="'.$oneThing.'" /&gt;&lt;br /&gt;';
  ?&gt;
  </code></pre>