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

Help needed displaying images in file

Guest
Oct 01, 2008 Oct 01, 2008
I have a directory of photographs that I wish to display one in a main folder and one in a folder called thumbs. Now there will always be a thumbs counterpart to the original image so for example I would like to display it:

<a href="123.jpg"><img src="thumbs/123.jpg"><br />123.jpg</a>

How can I have cold fusion cycle through files in a directory and do this for me?
375
Translate
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
Community Expert ,
Oct 01, 2008 Oct 01, 2008
<cfdirectory action="LIST" directory="#getDirectoryFromPath(expandPath('*.*'))#" filter="*.jpg" name="dir">
<cfloop query="dir">
<cfif dir.type is "file">
<!--- <div> --->
<cfoutput><a href="#dir.name#"><img src="thumbs/#dir.name#"><br />#dir.name#</a></cfoutput>
<!--- </div> --->
</cfif>
</cfloop>

Translate
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 ,
Oct 01, 2008 Oct 01, 2008
to even further simplify the code:

<cfdirectory
action="LIST"
listinfo="NAME"
directory="#expandPath('relative_path_to_images_dir_here')#"
filter="*.jpg"
name="qDir"
type="FILE">

<cfoutput query="qDir">
<!--- <div> --->
<a href="#qDir.name#"><img src="thumbs/#qDir.name#"><br
/>#qDir.name#</a>
<!--- </div> --->
</cfoutput>

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
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
Community Expert ,
Oct 01, 2008 Oct 01, 2008
Azadi wrote:
to even further simplify the code:...
A bit difficult to say.

<cfoutput query="qDir"><cfoutput>
I agree that yours is in general simpler than
<cfloop query="qDir"><cfoutput></cfoutput></cfloop>.
However, the comparison is not so obvious when there is text in the loop. I have indicated that with a div tag. There could be much more text to which it would be unnecessary to apply the cfoutput tag.

directory="#expandPath('relative_path_to_images_dir_here')#"
The hard-coded path limits the use of this code. You will have to rewrite it in certain situations.

type="FILE"
Coldfusion 8 introduced that attribute. So, for older versions, it is a complication, not a simplification.

In any case, PopcornCoder now has more to play with. Which can only be a good thing.

Translate
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 ,
Oct 01, 2008 Oct 01, 2008
iirc, type="file" existed in cfmx7, but was not documented.

same for listinfo="name", which significantly reduces the amount of data
returned by <cfdirectory> query.

also, your directory="#getDirectoryFromPath(expandPath('*.*'))#" will
query the directory the calling page is in, which is likely NOT to be
the directory the images are stored in.

and we both have omitted the recurse="no" attribute, which is important,
especially if the thumbs directory is inside the main images directory...

:)

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
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
Community Expert ,
Oct 02, 2008 Oct 02, 2008
LATEST
type="file" existed in cfmx7, but was not documented....same for listinfo="name"...
Really? Strange. The documentation says, "ColdFusion 8: Added the listinfo and type attributes."

also, your directory="#getDirectoryFromPath(expandPath('*.*'))#"
will query the directory the calling page is in, which is likely NOT
to be the directory the images are stored in.

The snippet href="123.jpg" tells me the calling page will quite likely be in the same directory as the images.

we both have omitted the recurse="no" attribute, which is
important, especially if the thumbs directory is inside the main
images directory...

I don't think we really have. When you omit it Coldfusion uses the default, which happens to be recurse="no". Also, you don't have to take the thumbnails into account when setting up cfdirectory. You get each thumbnail's path from the corresponding image.
Translate
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