The first thing we need to do is to define the save file path and the web path to the "myimages" folder which we will later query for the files.

<cfset imagepath = "C:\webroot\myimages">
<cfset imageURL =
"http://myserver/myimages">


<!--- first get a list of all jpg's in your image directory --->
<cfdirectory action="LIST" directory="#imagepath#" filter="*.jpg" name="homeimages">

<!--- This variable will hold a comma delimited list of all the jpg's found in the directory --->
<cfparam name="imglist" default="">
<cfloop query=
"homeimages">
    <cfset imglist = listappend(imglist, name,
",")>
</cfloop>


<!--- "ThisImage" is this rounds random image file --->
<cfset thisimage = listgetat(imglist, randrange(1, listlen(imglist)))>

<cfoutput>
    <img src="#imageURL#/#ThisImage#">
</cfoutput>

<!--- hope someone can use it and as always... Have fun! --->

About This Tutorial
Author: Bobby Hartsfield
Skill Level: Intermediate 
 
 
 
Platforms Tested: CF4,CF5
Total Views: 31,205
Submission Date: August 12, 2003
Last Update Date: June 05, 2009
All Tutorials By This Autor: 3
Discuss This Tutorial
Advertisement

Sponsored By...
Powered By...