<% '#FILE: random_image.asp - Version 1.3 '# '# This works on WindowsNT in an ASP environment. It has not '#been tested under any kind of Unix based platform running ASP. '# '#IMPORTANT: '# Make sure to save the METADATA tags above as well! They are '#needed to use DLL constants in this script! '# '#INSTALLATION INSTRUCTIONS: '# 1) Save this asp code to your server. '# 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) Change: '# Const IMAGE_DIRECTORY = "../pictures/" '# as described in the 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 with '# java release. '# ??/??/?? 1.2 Original release '# '#AUTHOR: '# http://www.davelozinski.com/scripts '# '#The system path to the directory (NOT URL!) which contains the '#images to be randomly chosen and displayed. '#Relative paths may be used. Const IMAGE_DIRECTORY = "../images/" '#If the program does not seem to be working for you, uncomment '#the next 3 lines by removing the apostrophe, and call this '#script separately. When the version number prints out, it needs '#to be at least 2.5. 'Set objConn = Server.CreateObject("ADODB.Connection") 'response.write "This Server's ADO Version: " & objConn.Version 'Set objConn = Nothing '##################################################################### '########Nothing below this line should need to be configured.######## '##################################################################### Randomize '#Initialize the random number generator Dim imageFiles '#Will hold each file in the directory Dim tempString tempString = "" Dim RandomNumber Dim File, Folder, fso Set fso = Server.CreateObject("Scripting.FileSystemObject") If (fso.FolderExists(Server.MapPath(IMAGE_DIRECTORY))) Then Set Folder = fso.GetFolder(Server.MapPath(IMAGE_DIRECTORY)) For Each File In Folder.Files tempString = tempString & File.Name & "," Next tempString = tempString & "," '#Puts a double comma to demark the end tempString = StrReverse(tempString) tempString = Replace(tempString, ",,", "", 1) tempString = StrReverse(tempString) imageFiles = Split(tempString, ",") RandomNumber = Cint((UBound(imageFiles) - LBound(imageFiles)) * Rnd + LBound(imageFiles)) Set File = Server.CreateObject("ADODB.Stream") File.Type = adTypeBinary '#Defined from MetaData tag at top File.Open File.LoadFromFile (Server.MapPath(IMAGE_DIRECTORY & imageFiles(RandomNumber))) '### To add support for additional image formats, just add in the appropriate '### lines below with the MIME-types. If (CBool(InStr(imageFiles(RandomNumber),".gif"))) Then Response.ContentType = "image/gif" ElseIf (CBool(InStr(imageFiles(RandomNumber),".jpg"))) Then Response.ContentType = "image/jpg" ElseIf (CBool(InStr(imageFiles(RandomNumber),".jpeg"))) Then Response.ContentType = "image/jpeg" End If Response.BinaryWrite File.Read File.Close End If Set File = Nothing Set Folder = Nothing Set fso = Nothing '#FILE: random_image.asp '##################################### %>