Solved

CFML question/problem with using cfdirectory

Posted on 2012-04-06
2
303 Views
Last Modified: 2012-06-22
This should be simple, and I'm sure it is :)  What I'm trying to accomplish is output a query of similar homes with photo, and if the property does not yet have a photo, display the no-photo.png graphic instead of a broken photo link.


====================================================================
<cfoutput query="similarhomes">
<cfif similarhomes.RecordCount EQ 0 OR similarhomes.subdivision IS "none"><cfelse>

<a href="/#urlencodedformat(trim(ListID))#/#StrNumber#-#StrName#-#Cty#-#St#.html" target="_blank">


<cfdirectory action="list" directory="#ExpandPath('/ftp/pics/')#" filter="#variables.IDnumber#.jpg" name="similarpics">
              <cfif similarpics.recordCount eq 0><img src="/images/no-photo.png" height="90" alt="no-photo" class="left" /><cfelse>

<img src="/ftp/pics/#ListID#.jpg" alt="#StreetNumber# #StreetName# #City# GA" width="130" height="90" class="left" /></cfif>

<h4>#StreetNumber# #StreetName#</a>
<br />
#City#, #State#</h4>
<br />
Price: #RemoveChars(DollarFormat(Price),Len(DollarFormat(Price))-3,3)#
<br />
SqFt: #TotalFinishedSQFT#
<br />
Bedrooms: #Bedrooms#
<br /><br />

 <hr />
 </cfif>
 </cfoutput>

================================================================
An example page where I'm running this code is at:http://199.73.57.154/103862/306-Estates-Way-Warner-Robins-GA.html the photos show up on the right column under "Similar Homes" the code above works as long as there is an existing photo, but still just shows a broken photo link if there is no photo.

As always, any help is greatly appreciated!
0
Comment
Question by:Bang-O-Matic
2 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 37816628
The if/else logic looks ok. But you're using a different value in the <cfdirectory> and <img> tags. That might explain why you're getting a broken image.  

Either use the same variable so you're sure the file exists

<cfdirectory action="list" directory="#ExpandPath('/ftp/pics/')#" filter="#variables.IDnumber#.jpg" name="similarpics">
<cfif similarpics.recordCount eq 0>
     <img src="/images/no-photo.png" />
<cfelse>
      <img src="/ftp/pics/#variables.IDnumber#.jpg" ... />
</cfif>

Or skip the directory list altogether. If you know the potential file name, just build the path and use FileExists and display "no-photo" when it returns false.
             
            <cfset pathToImage = ExpandPath("/ftp/pics/"& variables.IDnumber &".jpg")>
           <cfif FileExists(pathToImage)>
                   show the image
           <cfelse>
                   display "no-photo"
           </cfif>
0
 

Author Closing Comment

by:Bang-O-Matic
ID: 37823605
Perfect! thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now