Results: What level do you rate this at 

Voters
1 You may not vote on this poll

  • expert
    0%
  • advanced
    0%
  • some experience
    100.00%
  • beginger
    0%
    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Location
    Gold Coast, Australia
    Posts
    118
    Rep Power
    12

    Question show all images from a folder


    Hi,

    I am having some troubles where to beging this one. I am searching everywhere to find out how I can display all images contained in a particular folder.

    I am creating a portfolio, and only want to be able to just upload the image file to say, the logo's folder, and have that displayed automatically in the protfolio.

    I have been doing this by using a database as a midway communicator to tell CF that the image is there.

    Is it even possible? Well, we are talking about CF, so what am I saying, of course it is....

    Thanks Joe
    www.kobo.com.au | www.spicy.com.au

    "Some people are like Slinkies. They serve no useful purpose, but they're fun to push down the stairs."
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,243
    Rep Power
    967
    Why not use <cfdirectory> to read the contents of the directory, then loop over the results and only output the file if it has .gif or .jpg in the file name?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Location
    Gold Coast, Australia
    Posts
    118
    Rep Power
    12

    Talking


    Thanks kiteless,

    I did have that in mind (well not as clearly as you), but it seems to be on the complex side (I am quiete new to CF). I was hoping that there would be a read and display as image tag or something.

    Again, thanks for the advice.

    Joe
    www.kobo.com.au | www.spicy.com.au

    "Some people are like Slinkies. They serve no useful purpose, but they're fun to push down the stairs."
  6. #4
  7. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,243
    Rep Power
    967
    Nope, that's about the only way to do it. You could of course write a function or custom tag that you could reuse whenever you need that functionality. Either way, it's actually quite easy and would only take a few lines of code. Something like:

    <cfdirectory action="LIST" directory="#getDirectoryFromPath( getTemplatePath() )#/images/" name="directoryData">
    <cfoutput query="directoryData">
    <cfif findNoCase( '.jpg', directoryData.name ) or findNoCase( '.gif', directoryData.name )>
    <img src="images/#directoryData.name#">
    </cfif>
    </cfoutput>

    Obviously substitute your image directory if it differs from what I'm using above.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Location
    Gold Coast, Australia
    Posts
    118
    Rep Power
    12
    Your a savior...

    I have been trying to work out how to do this, and I now see what I missed out.

    I am pretty crappy at coding, but I learn.

    Thank you sooo much

    Joe

IMN logo majestic logo threadwatch logo seochat tools logo