Skip navigation
btvbillb
Currently Being Moderated

How to get CF to read file names from a folder and display?

Aug 8, 2012 10:07 AM

I have a folder with images and I'd like to have the image names displayed in a table, next to a corresponding customer number (which is pulled from a database) or if no image exists, then a noimage.jpg would disply as default. Can I do this in ColdFusion without having to reference image names from a database, etc.? For now, the images are just sitting in a folder. If so what code would I need to use? Thanks.

 
Replies
  • Currently Being Moderated
    Aug 8, 2012 10:17 AM   in reply to btvbillb

    If the image names are not in the database, how would the image be associated with the customer?  Is the image filename the customer name or id?

     

    ^_^

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 8, 2012 11:11 AM   in reply to btvbillb

    Are you looking for something more than what CFDIRECTORY does?

    -reed

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 8, 2012 11:23 AM   in reply to Reed Powell

    I was just going to suggest the same thing.  CFDIRECTORY (if it is turned on in CFAdmin) would be perfect. 

     

    ^_^

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 8, 2012 12:11 PM   in reply to btvbillb

    Need to understand whether the database is driving the list, or are the contents of the folder driving the list.  If you are looping through a query resultset from the database, that has the customer numbers and territory info, which is what it sounds like, then what you are really asking for (I think) is whether that customer's corresponding image file exists.  In which case you want the cf function named, you guessed it - fileExsits().

     

    If on the other hand you are driving this beast from whatever is in the folder, and looking for the corresponding data in the database, then use CFDIRECTORY and parse off the customer number in order to do the SELECT against the table.  But I don't think that is the scenario you are describing.

     

    Did either of those putts make it into the cup?

    -reed

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 8, 2012 12:33 PM   in reply to btvbillb

    As others have mentioned, cfdirectory will provide you with the file names.  You can query your db for other stuff and put it all together with Query of Queries.

     

    Some of the details might be tricky.  Good luck and post back if you have difficulty.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points