%@Language = VBScript %>
<% Option Explicit %>
<%
'#FILE: random_image2.asp - Version 2.0
'#
'#INSTALLATION INSTRUCTIONS:
'# 1) Save this asp code within the web page you want random images displayed.
'# It is recommended that you put this code at the top of your ASP page.
'# 2) Make sure the script has execute permissions.
'# 3) Make sure your DIRNAME has read permissions, as well
'# as the files within that directory.
'# 4) Change:
'# DIRNAME = "./images/"
'# as described in the asp code below.
'# 5) To display a random image, insert the following HTML ASP function call
'# within your HTML code:
'# DisplayRandomImage
'# See the HTML code below for an example.
'#
'#ABOUT THIS SCRIPT:
'# This is a very simple php script. All it does is grab a
'#random image from a directory and print the name within the associated
'#HTML IMG tag.
'#
'#HISTORY:
'# 5/15/2004 2.0 Upgraded so the function call isn't
'# within an IMG tag itself.
'# 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.
'#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/"
Const DIRNAME = "../images/"
'#The path RELATIVE to this script to the dir containing the images.
'#The value should end with a "/" character!
'#This directory should contain ONLY images.
'######## NOTHING BELOW THIS LINE SHOULD NEED TO BE CONFIGURED!!! ########
Function DisplayRandomImage
Dim images '#Holds the list of images to choose randomly from.
Dim msg '#Either the IMG tag or message to be returned.
Dim dir, fso, file, tempString '#Used for reading the folder and file names
tempString = ""
Set fso = Server.CreateObject("Scripting.FileSystemObject")
If (fso.FolderExists(Server.MapPath(DIRNAME))) Then
Set dir = fso.GetFolder(Server.MapPath(DIRNAME))
For Each file In dir.Files
tempString = tempString & file.Name & ","
Next
If (Len(tempString) > 0) Then
tempString = tempString & "," '#Puts a double comma to demark the end
tempString = StrReverse(tempString)
tempString = Replace(tempString, ",,", "", 1)
tempString = StrReverse(tempString)
images = Split(tempString, ",")
Set tempString = Nothing
Set dir = Nothing
Randomize
msg = "" & vbcrlf
Else
msg = "No random images located in """ & DIRNAME & """" & vbcrlf
End If
Else
msg = """" & DIRNAME & """ does not appear to be a valid directory!" & vbcrlf
End If
Set fso = Nothing
DisplayRandomImage = msg
End Function '#DisplayRandomImage
'########
%>
<%=DisplayRandomImage%>"