#!/usr/bin/perl # random-image.cgi %type = ( jpg=>'jpeg', jpeg=>'jpeg', gif=>'gif', png=>'png' ); srand(time|$$); opendir(DIR, ".") || die "$0: cannot open directory"; @filenames = grep(/\.(jpg|jpeg|gif|png)$/, readdir(DIR)); closedir(DIR); $maxFile = $#filenames; $whichFile = int(rand($maxFile + 1)); $theFile = $filenames[$whichFile]; $theFile =~ /\.(jpg|jpeg|gif)$/; $suffix = $1; print "Expires: Thu, 01 Dec 1994 16:00:00 GMT\n"; print "Content-type: image/$type{$suffix}\n\n"; open(G, "<$theFile") or die "Can't open file ($!)"; print ;