NoticeablyFAT Posted March 22, 2009 Share Posted March 22, 2009 Hello, I am extremely new to php, so I'm having some trouble figuring out just where to start with some of this stuff, which means I don't know what to look for to figure out what I need. So, on tho the question. I have a basic script set up to open a folder, read the files, then print a list of the files, sorted by date. This is then inserted into a small frame on my website. This all works just fine. What I'd like to do is create the list, then list only the last 10 files found. What functions would I use? Link to comment https://forums.phpfreaks.com/topic/150535-creating-a-list/ Share on other sites More sharing options...
trq Posted March 22, 2009 Share Posted March 22, 2009 Can we see your current code? Link to comment https://forums.phpfreaks.com/topic/150535-creating-a-list/#findComment-790696 Share on other sites More sharing options...
NoticeablyFAT Posted March 22, 2009 Author Share Posted March 22, 2009 What I have so far (actual paths changed for some semblance of privacy): <? function LoadFiles($dir) { $Files = array(); $It = opendir($dir); if (! $It) die('Cannot list files for ' . $dir); while ($Filename = readdir($It)) { if ($Filename == '.' || $Filename == '..') continue; $LastModified = filemtime($dir . $Filename); $Files[$LastModified] = $dir .$Filename; } return $Files; } $Files = LoadFiles('/home/something/public_html/somethingelse/cellpics/'); krsort($Files); //Replace path that opendir will read with path that works on page $Filepath = str_replace("/home/something/public_html/somethingelse/cellpics/", "http://mywebsite.com/cellpics/", $Files); foreach ($Filepath as $key => $file){ echo '<a href="'.$file.'">'.$file.'</a><br>'; } ?> I didn't write this, but I understand most of it. Link to comment https://forums.phpfreaks.com/topic/150535-creating-a-list/#findComment-790703 Share on other sites More sharing options...
NoticeablyFAT Posted March 22, 2009 Author Share Posted March 22, 2009 Ok, I figured it out. All I needed was "$Shortlist = array_slice($Files, 0, 10);", now it only displays the ten newest files. Link to comment https://forums.phpfreaks.com/topic/150535-creating-a-list/#findComment-790784 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.