Several years ago I got help here with the script below, which reads the files in a directory stored as YYYYMMDD.pdf and returns an HTML list.
Works great, but I need to modify this to limit the HTML list to only the 5 most recent files in the directory.
I tried playing with explode and that's not it.
<ul style="padding-left: 30px;">
<?
$the_array = Array();
$handle = opendir('images/stories/bulletins/2011/.');
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file != "index.html") {
$the_array[] = $file;
}
}
closedir($handle);
sort ($the_array);
reset ($the_array);
// leave the beginning of the script like you had before - get an array of filenames
foreach($the_array as $val) {
// this is the part you should change:
$filesplit = explode('.', $val);
$timestamp = strtotime($filesplit[0]);
$list = date('F j, Y',$timestamp);
echo "<li><a href=images/stories/bulletins/2011/$val>$list</a></li>";
}
?>
</ul>
Thanks for any pointers!