Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cfdirectory cfcontent - List image names and link 2

Status
Not open for further replies.

CTekMedia

Programmer
Joined
Oct 5, 2001
Messages
634
Location
US
I have a folder full of images. I would like to list the contents of the directory (cfdirectory) but make them appear as hyperlinks so the user can click on them and have the image display.

I am trying to avoid the work of listing them in a database.

Thanks much everyone,

Peace



BT
 
It's all in getting the path right.
Since CFDIRECTORY expects a physical path, and an HTML anchor tag (
Code:
<a>
) usually expects a relative path, and usually they aren't the same thing, you need to figure out how to give both tags what they want.

Code:
<!--- set this to the physical path down to webroot on your server --->
<CFSET sWebRootDirectory = &quot;/html/[URL unfurl="true"]wwwroot&quot;>[/URL]
<!--- set this to the path to your directory of images RELATIVE to webroot --->
<CFSET sImageDirectory = &quot;/somepath/images&quot;>

<!--- give CFDIRECTORY the concatenation of the physical path to webroot PLUS the relative path to the images directory... in this example, ColdFusion would see this path as &quot;/html/[URL unfurl="true"]wwwroot/somepath/images&quot;[/URL] --->
<CFDIRECTORY action=&quot;LIST&quot; directory=&quot;#sWebRootDirectory##sImageDirectory#&quot; name=&quot;qryDirectoryFiles&quot;>

<CFOUTPUT query=&quot;qryDirectoryFiles&quot;>
<!--- now give the anchor tag just the relative path to the image directory (plus the file name) --->
<a href=&quot;#sImageDirectory#/#qryDirectoryFiles.name#&quot;>#qryDirectoryFiles.name#</a><br />
</CFOUTPUT>


-Carl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top