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
Solved

CFML question/problem with using cfdirectory

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
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…

856 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