|
Display Random images in 3 lines of code!
Ever wanted to run random images on your site, but didn't want tons of code?
Here you go, every time the user refreshes the image is changed.
Put the contents below in a randomimg.cfm file and change the variables in red.
Then Call the image as in Include: <CFINCLUDE Template="randomimg.cfm">
|
<!--- Code Begins --->
<CFSET serverdir = "C:\INETPUB\WWWROOT\IMAGES\RANDOM\">
<CFSET httpdir = "http://www.yourserver.com/images/random">
<CFSET filter = "*.jpg OR *.gif">
(Note:
Only one single extension allowed)
<CFDIRECTORY
ACTION="list"
DIRECTORY="#serverdir#"
NAME="images"
FILTER="#filter#">
<CFSET index = RandRange(1, images.RecordCount)>
<cfoutput>
<img src="#httpdir#/#images.name[index]#">
</cfoutput>
<!--- Code Ends --->
|
|