Displaying images from a folder

Ask a Question related to Macromedia ColdFusion, Design and Development.

  1. #1

    Default Displaying images from a folder

    I'm trying to display all the images in a particular folder.

    I'm using this cfdirectory:

    <cfset thisPath = "\\daytona\cflr\images\vehicle\" & #URL.v# & "\sm\">
    <cfdirectory action="list" directory="#thisPath#" name="vehphoto">

    Daytona is a local CF (Windows 2003) server, cflr is a share on that server.
    I'm then using this to output the images:

    <cfoutput query="vehphoto">
    <img src="#thisPath##vehphoto.name#" width="98" alt="#rsFleet.MakeDesc#
    #rsFleet.ModelDesc# #rsFleet.Type#">
    </cfoutput

    After a fair bit of tinkering with the server, I got this to work ... but
    only in IE. Here's a snippet from View Source:

    <img src="\\daytona\cflr\images\vehicle\2\sm\DSCN5.jpg" width="98"
    alt="TVR">

    In both Opera and Firefox, only the contents of the alt attribute is
    displayed, as if the browser can't find the images.Is there something in IE
    that allows it to display images, or are Opera and Firefox at fault here?

    I must admit, I don't like using the \\server\share format, but can't see
    another way of doing it. I'm not sure how it's going to be handled when I
    move the site to a production server at an ISP. I would much prefer simply
    linking to the images as:

    <cfset image_src = "../images/vehicle/lg/#VehicleID#.jpg">
    <cfset image_pth = ExpandPath(image_src)>
    <img src="#image_src#" alt="#MakeDesc# #ModelDesc# #Type#" width="275"
    height="146" />

    but, of course, that's only suitable for single images, that I know the name
    of. I need to output all images in a particular folder (as the folder name
    will be the ID).

    Am I missing something glaringly obvious? Any help *much* appreciated!

    Andrew


    Andrew Guest

  2. Similar Questions and Discussions

    1. Help displaying images
      I am trying to display many pictures. I get all the file names in an array, cycle through the array creating image objects, then add them to the...
    2. Error Displaying Folder
      New install of ubuntu v5.10 puts a hda1 icon on the desk-top. Error message is displayed while opening. Error window:Error displaying...
    3. displaying images
      i am tying to display images dynamically on a product detail page based on a user selection on a page which displays a list of products. i am using...
    4. Displaying Images from Left to Right
      Good evening folks, I was wondering if there is a way to output a series of images in a table so that they list out from left to right. ...
    5. ASP Displaying Images from within SQL DB
      I've been searching and searching for this and there are lots of posts - but very few answers. I have a SQL2000 Database that has jpg images in a...
  3. #2

    Default Re: Displaying images from a folder

    You may want to consider writing a script that actually gets and displays the
    images. The UNC path works for IE images, but as you discovered, will not work
    with other browsers. This is probably a bad way to do it. Instead, write a
    special getImage script and use that as the image src. So the source may look
    like:

    <img src="getImage.cfm?img=\images\vehicle\2\sm\DSCN5.j pg" width="98"
    alt="TVR">

    Then in the getImage.cfm, use the CFCONTENT tag to get and output the image,
    such as:

    <CFCONTENT file="\\daytona\cflr\#img#" type="image/jpeg">

    Bryan



    blewis Guest

  4. #3

    Default Re: Displaying images from a folder

    Hi Bryan

    Thanks for the reply.
    > The UNC path works for IE images, but as you discovered, will not work
    > with other browsers.
    Really? I've not seen that documented anywhere. That would be remarkably
    short-sighted of Macromedia then!
    > This is probably a bad way to do it. Instead, write a
    > special getImage script and use that as the image src. So the source may
    > look
    > like:
    >
    > <img src="getImage.cfm?img=\images\vehicle\2\sm\DSCN5.j pg" width="98"
    > alt="TVR">
    >
    > Then in the getImage.cfm, use the CFCONTENT tag to get and output the
    > image,
    > such as:
    >
    > <CFCONTENT file="\\daytona\cflr\#img#" type="image/jpeg">
    Ah, but that's the problem. I don't know the name of the image files, nor
    how many there are; I just know the name of the folder they will be in. This
    is the stumbling block and it would seem that CFDIRECTORY is the only way to
    get that list.

    I believe the problem is in supplying the path to cfdirectory. Ideally, *the
    image source* would be in the order of :

    "../images/vehicle/sm/2/DSCN5.jpg"

    Currently, it is:

    "\\daytona\cflr\images\vehicle\2\sm\DSCN5.jpg"

    After you mentioned CFCONTENT, I turned to my trusty CF5 WACK and studied
    it. Adapting Ben's structure to get the list of images in a subfolder:

    <cfset VehDir = GetDirectoryFromPath(GetCurrentTemplatePath()) & "2\sm\">
    <cfdirectory directory="#VehDir#" action="list" filter="*.jpg"
    name="GetVeh">

    the image source is turned to:

    "C:\Inetpub\wwwroot\LR\fleet\2\sm\DSCN5.jpg"

    .... which, of course, doesn't show the images. I'm sure I'm missing
    something simple ... can you or anyone else help.

    <mumble>Be much easier in ASP ...</mumble>


    Andrew Guest

  5. #4

    Default Re: Displaying images from a folder

    I've sorted this ... and can't believe that I missed something so simple.
    Just in case others were wondering, here's the result:

    <cfset pthVehicle = GetDirectoryFromPath(GetCurrentTemplatePath()) & #URL.v#
    & "\sm\">
    <cfdirectory directory="#pthVehicle#" action="list" filter="*.jpg"
    name="rsVehImage">

    As expected, this will result in a listset comprising of:

    "C:\Inetpub\wwwroot\LR\fleet\2\sm\DSCN1.jpg"
    "C:\Inetpub\wwwroot\LR\fleet\2\sm\DSCN2.jpg"
    ....etc...

    The crucial difference, and the crucial thing that I missed, is that the IMG
    SRC still points to the relative folder, i.e. "../images/vehicle", *not* the
    path passed to cfdirectory.

    <cfoutput query="rsVehImage">
    <img src="../images/vehicle/#URL.v#/sm/#rsVehImage.Name#" width="98"
    alt="#rsFleet.MakeDesc#" />
    </cfoutput>

    <cfslap head = "hard">
    Doh!
    </cfslap>


    Andrew Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139