#!/usr/bin/perl -w # #FILE: random_image.pl - Version 1.3 # #INSTALLATION INSTRUCTIONS: # 1) Save this perl code to your cgi-bin directory, or wherever # cgi/perl scripts can be executed on your system. # 2) Make sure the script has execute permissions. # 3) Make sure your $IMAGE_DIRECTORY has read permissions, as well # as the files within that directory. # 4) Need to change the first line: # !/usr/bin/perl # to point to perl on your system. # 5) Change: # $IMAGE_DIRECTORY = "../pictures/"; # as described in the perl code below. # 6) Make your IMG tag look similar to the following: # # #ABOUT THIS SCRIPT: # This is a very simple perl script. All it does is grab a #random image from a directory and print it out, hiding the actual #filename of the image displayed. Currently, this #script just works with gif and jpg/jpeg images. # #HISTORY: # 05/21/04 1.3 Updated with some streamlined code for java release. # ??/??/?? 1.2 UPdated with ASP release # ??/??/?? 1.1 Made to work under both Unix and Windows with # PHP release # ??/??/?? 1.0 Original release # #AUTHOR: # http://www.davelozinski.com/scripts # #BEGIN CONFIGURATION ITEMS: #The full path listing to the directory which contains the images #to be randomly chosen and displayed. #Unix users should be able to get away with specifying a relative path. #NT users may have to specify the full system path, which will probably #need to look similar to: #"c:\\wwwroot\\htdocs\\images\\" or #"f:/Inetpub/wwwroot/images/" # $IMAGE_DIRECTORY = "../pictures/"; ###Nothing below this line should need to be configured.### my $line = ""; my $randomNumber= 0; my @imageFiles; my $x=0; if (opendir (DIR,"$IMAGE_DIRECTORY")) { while ($fileName = readdir(DIR)) { next if (-d $IMAGE_DIRECTORY . $fileName); next if ($fileName !~ /\w/); if ($fileName =~ /\.gif$|\.jpg$|\.jpeg$/i) { $imageFiles[$x] = $fileName; $x+=1; } } closedir(DIR); srand(); $randomNumber = int(rand(@imageFiles)); print ("Pragma: no-cache\n"); if ($imageFiles[$randomNumber] =~ /\.gif$/i) { print ("Content-type: image/gif\n\n"); } elsif ($imageFiles[$randomNumber] =~ /\.jpg$|\.jpeg$/i) { print ("Content-type: image/jpg\n\n"); } else { #Not a gif or jpeg file. Exit the program. exit(0); } open (INPUT, $IMAGE_DIRECTORY . $imageFiles[$randomNumber]); while ($line = ) { #Print the image out to the browser. print ($line); } close(INPUT); } exit(0); #FILE: random_image.pl #####################################