• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 321
  • Last Modified:

file exist

Hi,

I want to say if the image does not exist in my folder don't display the image.

<cfif isdefined("url.AdID") and Evaluate('DispEdit.PathImage' & i) neq ''>

//something is wrong with this code belong
<cfif len('DispEdit.PathImage' &i) and fileExists(expandPath('DispEdit.PathImage' &i))>

<img src="<cfoutput>#Evaluate('DispEdit.PathImage' & i)#</cfoutput>"
                                                         width="70px" height="63px"/>
                                                       </cfif>
                                                        
                                                         <br>
                                                         </cfif>
0
lulu50
Asked:
lulu50
  • 3
  • 2
1 Solution
 
gdemariaCommented:

Here's some new code to try.

First, since displEdit is a structure, I use structKeyExists to test to see if the pathImage1 exists
Then, I copy the value of it into a new, simple variable, so we don't have to keep using evaluate() several times (it's best never to use evaluate anyway, use the structure format indicated below).

I removed the test to see if it was empty, it's the same thing as testing if there is a length.

I added a couple output statements to help see what's happening if it doesn't work.. does it show image does not exist or does it show "now showing.."

Let me know if this doesn't work and what it is showing...

<!---- does AdID exist and does the pathImage for i exist inside of dispEdit -->
<cfif isDefined("url.AdID") ans structKeyExists(dispEdit,"pathImage#i#")>
  <!---- put the pathe image for i into a new variable to make it easier -->
  <cfset thePathImage = trim(DispEdit["PathImage" & i])> <!--- don't use evaluate, especially on structures -->
  <cfif len(thePathImage) and fileExists(expandPath(thePathImage))>
     <cfoutput>
     <h2>Now showing image [#thePathImage#]</h2>
     <img src="#thePathImage#" width="70px" height="63px"/>
     </cfoutput>
  </cfif> 
<cfelse>
   <h2>Image does not exist [#expandPath(thePathImage)#]</h2>
</cfif>

Open in new window

0
 
lulu50Author Commented:
I am getting an error because of this line.


<cfset thePathImage = trim(DispEdit["PathImage" & i])>

-----------------------------------------------

Complex object types cannot be converted to simple values.  
The expression has requested a variable or an intermediate expression result as a simple value, however, the result cannot be converted to a simple value. Simple values are strings, numbers, boolean values, and date/time values. Queries, arrays, and COM objects are examples of complex values.
The most likely cause of the error is that you are trying to use a complex value as a simple one. For example, you might be trying to use a query variable in a <CFIF> tag. This was possible in ColdFusion 2.0 but creates an error in later versions.
 
0
 
gdemariaCommented:
Ok, the question is... what is "'DispEdit"  ?  

I thought it was a structure, but is must be a query.. is that right?

So here it is again treating dispEdit as a query...

 
<!---- does AdID exist  ---->
<cfif isDefined("url.AdID")>
  <!---- put the pathe image for i into a new variable to make it easier -->
  <cfset thePathImage = trim(DispEdit["PathImage" & i][DispEdit.currentRow])> <!--- don't use evaluate, especially on structures -->
  <cfif len(thePathImage) and fileExists(expandPath(thePathImage))>
     <cfoutput>
     <h2>Now showing image [#thePathImage#]</h2>
     <img src="#thePathImage#" width="70px" height="63px"/>
     </cfoutput>
  </cfif> 
<cfelse>
   <h2>Image does not exist [#expandPath(thePathImage)#]</h2>
</cfif>

Open in new window



When accessing a query's row and column dynamically (using a variable) you would use this syntax...

myQuery[ColumnName][RowNumber]

This allows you to access any value in your query without looping through it.  For example, you can get the first name of the 10th record by doing this...


myQuery["firstName"][10]

So in your case, we are getting the imagePath (of 1, 2, 3, 4 depending on i's value) of the current record which is written like this...

   DispEdit["PathImage" & i][DispEdit.currentRow]

0
 
lulu50Author Commented:
Yes, it is a query "DispEdit"

it works great now.  

Thank you.  gdemaria for your help!!!!

I now need to think of a way to remove the overflow images from my folder.

I will post a new question for it soon.

0
 
lulu50Author Commented:
Thank you
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now