# #ABOUT THIS SCRIPT: # This is a very simple php 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: # ??/??/?? 1.3 Updated and streamlined the code with # release of java version # ??/??/?? 1.2 Updated with ASP release # ??/??/?? 1.1 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 = "../images/"; ###Nothing below this line should need to be configured.### $line = ""; $randomNumber= 0; $imageFiles = array(); $fileName = ""; $x=0; if ($DIR = opendir($IMAGE_DIRECTORY)) { while ($fileName = readdir($DIR)) { if (is_dir($IMAGE_DIRECTORY . $fileName)) { continue; } if (!preg_match("/\w/", $fileName)) { continue; } if (preg_match("/\.gif$|\.jpg$|\.jpeg$/i",$fileName)) { $imageFiles[$x] = $fileName; $x+=1; } } closedir($DIR); srand((double)microtime()*1000000); $randomNumber = rand(0,(count($imageFiles) - 1)); Header ("Pragma: no-cache\n"); if (preg_match("/\.gif$/i",$imageFiles[$randomNumber])) { Header ("Content-type: image/gif\n\n"); } elseif (preg_match("/\.jpg$|\.jpeg$/i",$imageFiles[$randomNumber])) { Header ("Content-type: image/jpg\n\n"); } else { #Not a gif or jpeg file. Exit the program. exit; } $fp = fopen ($IMAGE_DIRECTORY . $imageFiles[$randomNumber], "rb"); echo (fread($fp,filesize($IMAGE_DIRECTORY . $imageFiles[$randomNumber]))); fclose($fp); } exit; # random_image.php ?>