How do I get a random image from a directory?
Use the RandRange function to pick a random image file form your directory.
<cfset imagepath = "images/gallery/" />
<cfdirectory directory="#ExpandPath(imagepath)#"
filter="*.jpg|*.gif"
name="qryImages"
action="list" />
<img src="#imagepath##qryImages.name[RandRange(1, qryImages.RecordCount)]#" />
<cfdirectory directory="#ExpandPath(imagepath)#"
filter="*.jpg|*.gif"
name="qryImages"
action="list" />
<img src="#imagepath##qryImages.name[RandRange(1, qryImages.RecordCount)]#" />
This question was written by John Whish.
It was last updated on July 10, 2008 at 10:27:34 AM EDT.
Categories
Comments
There are no comments for this entry.