Another Cheap Thumb Gallery Maker

One thing about scripting is that, sometimes, a little fragment of code will get used over and over, and it's not a full-featured app. This script just looks over a directory full of specially named files, and produce a "photo gallery" for it.

Hundreds of these scripts have been modified to do all kinds of cool things, but this one doesn't do any of those things. The script just gets copied into a directory, and it produces an index of images.

Scripts like this won't ever die. They won't get replaced by more elaborate scripts. They've evolved to fit their niche.

<?php // vi:set ts=4 sw=4 ai:

$files = array();
$dh = opendir('.');
while( $d = readdir($dh) )
{
    if (preg_match('/-400.jpg/', $d))
    {
        array_push( $files, $d );
    }
}
sort($files);
foreach( $files as $d )
{
    $t = preg_replace('/-400/','-800', $d);
    list( $width, $height ) = getimagesize( $d );
    $path = preg_replace('/index\\.php/','',$_SERVER['REQUEST_URI']);
    echo "&lt;a href='$path/$t' target='_blank'>&lt;img src='$path/$d' width='$width' height='$height' border='0' />&lt;/a>&lt;br />&lt;br />";
}
?>