> the appropriate
> icon:
> function Image(filename){
> var ext = "";
> var img = "empty";
> if(ListLen(filename,".") GT 1) ext =
> ListLast(filename,".");
> else if(ListFindNoCase("doc,rtf",ext)) img = "doc";
> else if(ListFindNoCase("xls,csv",ext)) img = "xls";
> else if(ListFindNoCase("ppt",ext)) img = "ppt";
> else if(ListFindNoCase("mdb",ext)) img = "mdb";
> else if(ListFindNoCase("pdf",ext)) img = "pdf";
> else if(ListFindNoCase("zip",ext)) img = "zip";
> else if(ListFindNoCase("mp3",ext)) img = "mp3";
> else if(ListFindNoCase("gif,png",ext)) img = "gif";
> else if(ListFindNoCase("jpg,jpeg",ext)) img = "jpeg";
> else if(ListFindNoCase("txt",ext)) img = "txt";
> else if(ListFindNoCase("htm,html",ext)) img = "html";
> return img & ".gif";
> }
I agree with the function, although a switch or better yet a structure
would be more versatile and more efficient. I'd create a separate
directory for the images and name the image to match the file
extensions, then use the directory to create a structure in the
request scope (or better yet cached in the application scope) and use
that structure to check to see if an image exists for a given file
type:
application.cfm
<cfif not structkeyexists(application,"ext")>
<cfset st = structnew()>
<cfdirectory name="rsext"
directory="#extImgDir#>
<cfloop query="rsext">
<cfset myext = rereplace(rsext.name,"\.[^.]+$","")>
<cfset st[myext] = rsext.name>
</cfloop>
<cfset application.ext = st>
</cfif>
<cfscript>
function extImg(filename) {
var myext = listlast(filename,".");
if (structkeyexists(application.ext,myext)) {
filename = application.ext[myext];
} else { filename = "txt.gif"; }
return "/pathtographics/" & filename;
}
</cfscript>
index.cfm
<cfoutput query="myfiles">
<div><a href=""> <img src="" />
#myfiles.name#
</div>
</cfoutput>
The really nice thing about this is that once it's written, you never
have to edit it to add new file types, all you have to do is put the
image in that directory and you're done.
ike
s. isaac dealey 954.927.5117
new epoch : isn't it time for a change?
add features without fixtures with
the onTap open source framework
http://www.sys-con.com/story/?storyid=44477&DE=1
http://www.sys-con.com/story/?storyid=45569&DE=1
http://www.fusiontap.com
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

