Random Images In a Few lines of code

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 --->
 
All ColdFusion Tutorials By Author: DesertTRD
  • Random Images In a Few lines of code
    Ever wanted to run random images on your site, but didnt want tons of code? Here you go, every time the user refreshes the image is changed.
    Author: DesertTRD
    Views: 17,236
    Posted Date: Friday, August 15, 2003
Download the EasyCFM.COM Browser Toolbar!