#!/usr/bin/perl -w use CGI; # Where the image files are. my $imagedir="images"; # You shouldn't need to change this. my @file_types=qw/ jpeg jpg jp2 jfif jng png mng gif bmp /; # == # Nothing changes below here. my %file_types_h; @file_types_h{@file_types}=@file_types; my $cgi=new CGI; sub cdie { print $cgi->header("text/plain"); print "ERROR: "; print @_; exit; } opendir(IDIR, $imagedir) or cdie("Data directory not readable"); my @items=map {"$imagedir/$_"} grep {m/\.(\w+)$/ and $file_types_h{$1} and -r "$imagedir/$_"} readdir IDIR; closedir IDIR; cdie("No images to choose from!") unless @items; print $cgi->redirect($items[rand @items]);