#!/usr/bin/perl # #FILE: rnd_splash.pl - Version 1.2 # # This program now works with both Unix and WindowsNT # # This is a very simple perl script. All it does is grab a #random image from a directory and print it out. Currently, this #script just works with gif and jpg/jpeg images. To call this #script from your HTML page: # 1) Copy the perl script to your cgi-bin directory, or wherever #cgi 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) Make your IMG tag look similar to the following: # # #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\\" $IMAGE_DIRECTORY = "../images/rnd_images/splash_b/"; ###Nothing below this line should need to be configured.### my $line = ""; my $file1= ""; my $x=0; opendir (DIR,"$IMAGE_DIRECTORY"); while ($fileName = readdir(DIR)) { next if (-d $IMAGE_DIRECTORY . $fileName); next if ($fileName !~ /\w/); $ls[$x] = $fileName; $x+=1; } closedir(DIR); srand(time ^ $$); srand(); $file1 = int(rand(@ls)); print ("Pragma: no-cache\n"); if ($ls[$file1] =~ /\.gif$/i) { print ("Content-type: image/gif\n\n"); } elsif ($ls[$file1] =~ /\.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 . $ls[$file1]); while ($line = ) { #Print the image out to the browser. print ($line); } close(INPUT); exit(0); #FILE: rnd_splash_X.pl #####################################