pf » Build a directory browser with ColdFusion
Build a directory browser with ColdFusion
Most web servers have directory browsing disabled, but sometimes you want it to work for certain directories. Most web servers also allow you to setup specific settings for your directories for instance you could do it with an .htaccess file on Apache. But if you don't have access to your web server, you can create a directory index pretty easily with ColdFusion's cfdirectory tag.
I have whipped up a simple one you can use, just save the following code as index.cfm in the directory where you want to see a file listing:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title><cfoutput>#Replace(cgi.script_name, "index.cfm", "")#</cfoutput></title>
<style type="text/css">
body,td { font-family: verdana; padding: 2px 0px 2px 0px; color:silver; }
th { border-bottom: 1px solid silver;text-align:left;margin-bottom: 2px; color:black; }
a.sort { text-decoration: none; color: silver; }
a:hover { background-color: blue; color: white; }
p { font-size: x-small; }
</style>
</head>
<body>
<cfparam name="url.sort" default="datelastmodified desc">
<cfdirectory directory="#ExpandPath("./")#" action="list" name="dir" sort="#url.sort#">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<th>Name <a href="?sort=name" class="sort" title="Sort By Name">∨</a></th>
<th>Size (bytes) <a href="?sort=size" class="sort" title="Sort By Size">∨</a></th>
<th>Last Modified <a href="?sort=datelastmodified+desc" class="sort" title="Sort By Date">∨</a></th>
</tr>
<cfoutput query="dir">
<cfif dir.name IS NOT "index.cfm">
<tr>
<td><a href="#dir.name#">#dir.name#</a></td>
<td>#dir.size#</td>
<td>#dir.datelastmodified#</td>
</tr>
</cfif>
</cfoutput>
</table>
<p>Directory Browser by <a href="http://www.petefreitag.com/">Pete Freitag</a></p>
</body>
</html>
You can see a slightly modified version of this script on the daily mashup archives page.
Related Entries
- CFSCRIPT Cheatsheet - May 5, 2008
- ColdFusion 8 Update 1 Fixes some Image Processing Quirks - April 5, 2008
- 10 Most Useful Image Functions in ColdFusion 8 - April 5, 2008
- ColdFusion 8 Image Manipulation Presentation Recording - October 26, 2007
- CFImage Effects Library for ColdFusion 8 - August 9, 2007
Any thoughts?
Here's my attempt: http://uffcanadianpartners.com/agent/files/index2.cfm
Perhaps I'm supposed to change some of that stuff to my own site-specific; but I don't know cf to be able to figure out which. Might you have the time for a quick eyeball? Thanks -- Don
I get a 404 File not Found error when trying to access that file. But chances are if you don't ColdFusion installed. You can get it from Adobe.com
Apache does have a built in mechanism for directory browsing. See my apache cheat sheet for an example: http://www.petefreitag.com/cheatsheets/apache/
- CFSCRIPT Cheatsheet
- 3 New Image Effects for ColdFusion 8
- Googlebot to Submit Web Forms
- ColdFusion 8 Update 1 Fixes some Image Processing Quirks
- 10 Most Useful Image Functions in ColdFusion 8
- Speaking at NYC CFUG This Week
- Adobe AIR Tutorial for HTML / JavaScript Developers
- INFORMATION_SCHEMA Support in MySQL, PostgreSQL
RSS
add to del.icio.us
Pete Freitag is a software engineer, and web developer located in










