#!/usr/bin/perl -w use strict; use CGI qw(:standard); use CGI::Carp; my $path = "/path/to/images"; my $imagereq = param('iwant'); $imagereq ||= 0; # defaults to image 0 my $image_path = "$path/$imagereq.jpg"; # check there are digits only in the request and that the file exists $image_path = "$path/404.jpg" unless $imagereq =~ /^\d+$/ and -e $image_path; open(IMAGE, "<", $image_path) or die "ACK! $!"; print "Content-type: image/jpeg\n\n"; binmode STDOUT; $/ = \8192; # read data in 8kbyte chunks rather than from LF to LF # see perldoc perlvar print while ;