Using a file directory as a database

Discussion in 'Programming' started by Rahne, Nov 2, 2007.

  1. #1
    Hello,

    I'm trying to use a file directory on my ftp server as a database. Here's the application: I have a camera taking pictures every so often and I would like to output the last image taken on a site I've created.

    I figured using datelastmodified would be the simplest solution, but I can't seem to figure out how to pull the last image without importing all that information into a access or sql database (I'm a novice if you can't tell :D ). Has anyone done this?
     
    Rahne, Nov 2, 2007 IP
  2. Jamie18

    Jamie18 Peon

    Messages:
    201
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    here is a quick bit of code you can play with..

    <cfdirectory action="LIST" sort="datelastmodified desc" directory="C:\your full image directory path" name="dir">

    <cfoutput>
    <img src="directory path(relative or absolute)\#dir.name[1]#">
    </cfoutput>

    the cfdirectory tag brings back a list of files, the sort="datelastmodified desc" ensures they are sorted from most recent to least recently modified..

    dir.name[1] returns the filename of the most recently modified file in the directory.

    if you want a look at all the other attributes you have access to do a <cfdump var="#dir#">
     
    Jamie18, Nov 2, 2007 IP
  3. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Jamie18 has got the right idea :)

    While cfdirectory is probably the simplest solution, its not the best solution over time. The more files you have, the larger and slower the query. Ultimately a database is the better solution since it allows you retrieve only what you need (ie one record).
     
    cfStarlight, Nov 2, 2007 IP