jjmusicpro Posted July 23, 2008 Share Posted July 23, 2008 Hi, im not sure if php can do this, but i wanted to look at specific folder like /images/ and have it grab the last 10 that were added in there, is this possible? I then wanted to display them out on my page. Link to comment https://forums.phpfreaks.com/topic/116102-solved-look-into-folder-and-get-latest-files-added/ Share on other sites More sharing options...
trq Posted July 23, 2008 Share Posted July 23, 2008 Not tested but something liek the following should go pretty close. <?php $files = array(); // grab all files within the /images directory foreach (glob("/images/*") as $file) { // place them into an array using modification times as key. $files[filemtime($file)] = $file; } // sort array keys from newest to oldest arsort($files); // display 10 latest files. $i = 1; foreach ($files as $filemtime => $file) { echo $file . "<br />"; $i++; if ($i == 10) { break; } } ?> Link to comment https://forums.phpfreaks.com/topic/116102-solved-look-into-folder-and-get-latest-files-added/#findComment-597033 Share on other sites More sharing options...
jjmusicpro Posted July 23, 2008 Author Share Posted July 23, 2008 how do i make it so it displays the file? Then a box underneith with a copy and paste imge tag with html. Link to comment https://forums.phpfreaks.com/topic/116102-solved-look-into-folder-and-get-latest-files-added/#findComment-597038 Share on other sites More sharing options...
jjmusicpro Posted July 23, 2008 Author Share Posted July 23, 2008 i figured it out thanks again! Link to comment https://forums.phpfreaks.com/topic/116102-solved-look-into-folder-and-get-latest-files-added/#findComment-597042 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.