Notice: With the launch of Adobe Cookbooks, this site will no longer be accepting new entries or posting new content. Thanks to everyone who submitted content!

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)]#" />


This question was written by John Whish.
It was last updated on July 10, 2008 at 10:27:34 AM EDT.

Categories

Images

Comments

There are no comments for this entry.