• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Explorer ,
Aug 08, 2012 Aug 08, 2012

Copy link to clipboard

Copied

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.

Views

991

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 08, 2012 Aug 08, 2012

Copy link to clipboard

Copied

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?

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 08, 2012 Aug 08, 2012

Copy link to clipboard

Copied

Yes, its based on the customer number, ie.

<td width="74%" align="left" valign="top"><img src="../RepInformation/images/#CustomerNumber#.png" onerror="this.src='../RepInformation/images/noImage.gif';"></td>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 08, 2012 Aug 08, 2012

Copy link to clipboard

Copied

Are you looking for something more than what CFDIRECTORY does?

-reed

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 08, 2012 Aug 08, 2012

Copy link to clipboard

Copied

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

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 08, 2012 Aug 08, 2012

Copy link to clipboard

Copied

Probably. I don't need it to just print a list of files. I need it to display each individual image file name to the right of each record. Here is a screenshot of the tabel I have to add it to. Right after Territry, I need a column with 11871.jpg, 11899.jpg, etc and then any record without an image would show "noimage.jpg". Hope this makes sense.

Capture.PNG

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 08, 2012 Aug 08, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 08, 2012 Aug 08, 2012

Copy link to clipboard

Copied

Thanks Reed. Both columns pull from a database but the images are not in the database, but in a folder and are referenced only by the line of code in number 2 above.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 08, 2012 Aug 08, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 08, 2012 Aug 08, 2012

Copy link to clipboard

Copied

LATEST

Thanks everybody. I got it to work. Here is my code in case someone else needs help:

  <td>#CustomerName#</td>
  <td>#CustomerNumber#</td>
  <td><cfif FileExists("\\ncc1701-01\web\Sales\Information\images\#CustomerNumber#.png")>
        YES
    <cfelse>
        NO
    </cfif></td>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation