PHP: Contemporary Recent Files

This is the technique I used at WNLibrary to list recent additions:

<!-- modPDF.php <k0nsl> -->

<div class="maintitle">Recently Added eBooks:</div>
<p><br><center><a href="/?new"><img src="/graphs/My-Ebooks-icon.png" border="0" title="" alt="" /></a></center></p>
<br>
<?php
$show = 5; /* amount of files to list */
$mdir = '/home/WNLibrary/public_html/stack/Portabel Documents/'; /* don't forget trailing-slash */

if($mdir) chdir($mdir);

$files = glob( '*.{pdf}', GLOB_BRACE );
usort( $files, create_function('$b, $a', 'return filemtime( $a ) - filemtime( $b );') );

for ( $i = 0; $i < $show; ++$i )
    echo '&#171; <a href="/Portabel Documents/', $file = $files[$i], '">', $file, '</a><br />', "\n";

?>

Leave a Reply

Your email address will not be published. Required fields are marked *