View Single Post
Old 12-28-2008, 05:56 PM   #1 (permalink)
Lou_Gato
The Wanderer
 
Join Date: Oct 2008
Posts: 14
Thanks: 0
Lou_Gato is on a distinguished road
Default Happy Holidays Everyone! now to my question : ) limiting results from read dir

ok I learned how to read dir, and list the results.. now my issue is can i limit the results from the directory to only the 3 most recent files in that directory? lets say that the files are images, and I would only like to see the latest three images in that directory. no more. how would i achieve this?


Code:
<?
  $desired_extension = 'jpg'; //extension we're looking for
  $dirname = "../thumbs/";
  $dir = opendir($dirname);

  while(false != ($file = readdir($dir)))
  {
    if(($file != ".") and ($file != ".."))
    {
      $fileChunks = explode(".", $file);
      if($fileChunks[1] == $desired_extension) //interested in second chunk only
      {      
        echo '<a href="http://online-tech.com/clubtoni/thumbs/'.$file.'"> '.$file.'</a></br>';
      }
    }
  }
  closedir($dir);
?>
Lou_Gato is offline  
Reply With Quote