<!--- Directory to scan for images --->
<CFSET Dir = ExpandPath("../images")>

<!--- Get GIF and JPG file listing, via custom tag --->
<CF_GetDirectoryContents
  Directory="#Dir#"
  Filter="*.gif;*.jpg"
  ReturnVariable="GetFiles">

<!--- Get films from database, including image name --->  
<CFQUERY NAME="GetFilms" DATASOURCE="#REQUEST.DataSource#">
  SELECT FilmID, MovieTitle, ImageName 
  FROM Films
  ORDER BY MovieTitle
</CFQUERY>

<!--- Join database  --->
<CFQUERY NAME="GetJoined" DBTYPE="query">
  SELECT 
    GetFilms.FilmID           AS FilmID, 
    GetFilms.MovieTitle       AS MovieTitle,
    GetFilms.ImageName        AS ImageName, 
    GetFiles.Name             AS ImageOnDisk, 
    GetFiles.Size             AS FileSize, 
    GetFiles.DateLastModified AS DateLastModified
  FROM
    GetFilms LEFT OUTER JOIN GetFiles
    ON GetFilms.ImageName = GetFiles.Name
  ORDER BY GetFilms.MovieTitle
</CFQUERY>


<HTML>
<HEAD><TITLE>Film Images</TITLE></HEAD>
<BODY>
<H2>Film Images</H2>

<!--- Display all files together as HTML Table --->
<CFOUTPUT>
  <TABLE BORDER="1">
    <TR>
      <TH>Film</TH>
      <TH>Image Name</TH>
      <TH>Actual Image</TH>
      <TH>File Size</TH>
    </TR>
    <CFLOOP QUERY="GetJoined">
      <TR>
        <TD>#MovieTitle#</TD>
        <TD>#ImageName#</TD>
        <TD>
          <!--- Show "*missing*" msg in red if meant --->
          <!--- to have image, but no actual file... --->
          <!--- Otherwise, show simple link to image --->
          <CFIF (ImageName NEQ "") AND (ImageOnDisk EQ "")>
            <FONT COLOR="Red">*missing*</FONT>
          <CFELSE>
            <A HREF="../images/#ImageName#">#ImageName#</A> 
          </CFIF>
        </TD>
        <TD>#Round(FileSize / 1024)# K</TD>
      </TR>
    </CFLOOP>  
  </TABLE>
</CFOUTPUT>

</BODY>
</HTML>


