title: Sort images by exif data in php
body: <p>I'm new to php and I'm trying to figure out how to sort images by exif creation date. The code below is the one from this tutorial I followed: <a href="http://www.lateralcode.com/simple-php-gallery-pagination/" rel="nofollow">Simple Php Gallery Pagination</a></p>
  
  <p>I just modified a little bit to retrieve exif data
  I'm looking for a method without database, the goal is to have a paginated gallery (and now it is paginated) sorted with newest first</p>
  
  <pre><code>function getPictures() {
      global $page, $per_page, $has_previous, $has_next, $DirFoto, $DirThumb;
      if ( $handle = opendir($DirFoto) ) {
  
          echo '&lt;ul id="pictures"&gt;';
  
          $count = 0;
          $skip = $page * $per_page;
  
          if ( $skip != 0 )
              $has_previous = true;
  
          while ( $count &lt; $skip &amp;&amp; ($file = readdir($handle)) !== false ) {
              if ( !is_dir($file) &amp;&amp; ($type = getPictureType($file)) != '' )
                  $count++;
          }
          while ( $count &lt; $per_page &amp;&amp; ($file = readdir($handle)) !== false ) {
              if ( !is_dir($file) &amp;&amp; ($type = getPictureType($file)) != '' ) {
  
                  $exif = exif_read_data("$DirFoto/$file", 0, true);                  
  
                  if ( ! is_dir($DirThumb) ) {
                      mkdir($DirThumb);
                  }
                  if ( ! file_exists($DirThumb.'/'.$file) ) {
                      makeThumb( $file, $type );
                  }
                  echo '&lt;li&gt;&lt;a href="'.$DirFoto.'/'.$file.'" title="Photo taken on '.date("F d Y, H:i:s", strtotime($exif['IFD0']['DateTime'])).'"&gt;';
                      echo '&lt;img src="'.$DirThumb.'/'.$file.'" alt="'.date("F d Y, H:i:s", strtotime($exif['IFD0']['DateTime'])).'"/&gt;';   
                  echo '&lt;/a&gt;&lt;/li&gt;';
                  $count++;
              }
          }
          echo '&lt;/ul&gt;';
  
  
  
          while ( ($file = readdir($handle)) !== false ) {
              if ( !is_dir($file) &amp;&amp; ($type = getPictureType($file)) != '' ) {
                  $has_next = true;
                  break;
              }
          }
  
  
      }
  }
  </code></pre>