Solved

CFML question/problem with using cfdirectory

Posted on 2012-04-06
2
306 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

730 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