?
Solved

CFML question/problem with using cfdirectory

Posted on 2012-04-06
2
Medium Priority
?
310 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
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 …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

762 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