Skip to main content
May 5, 2010
Question

FileExists Error

  • May 5, 2010
  • 1 reply
  • 1282 views

<cfoutput>
<cfset baseurl = "http://www.1.com">
<cfset PhotoLocation1 ="#baseurl#/candy_apples/thumbs/#url.itemnumber#.jpg">
<cfset PhotoLocation2 ="#baseurl#/caramel_corn/thumbs/#url.itemnumber#.jpg">
    <cfset PhotoLocation3 ="#baseurl#/carnival_games/thumbs/#url.itemnumber#.jpg">
    <cfset PhotoLocation4 ="#baseurl#/cleaning_products/thumbs/#url.itemnumber#.jpg">
    <cfset PhotoLocation5 ="#baseurl#/cold_beverages/thumbs/#url.itemnumber#.jpg">
    <cfset PhotoLocation6 ="#baseurl#/fudge_puppies/thumbs/#url.itemnumber#.jpg">
    <cfset PhotoLocation7 ="#baseurl#/funnel_cakes/thumbs/#url.itemnumber#.jpg">
    <cfset PhotoLocation8 ="#baseurl#/golden_cafe_coffee/thumbs/#url.itemnumber#.jpg">
    <cfset PhotoLocation9 ="#baseurl#/hot_dogs/thumbs/#url.itemnumber#.jpg">
    <cfset PhotoLocation10 ="#baseurl#/kettle_corn/thumbs/#url.itemnumber#.jpg">
    <cfset PhotoLocation11 ="#baseurl#/lighted_menu_signs/thumbs/#url.itemnumber#.jpg">
    <cfset PhotoLocation12 ="#baseurl#/miscellaneous/thumbs/#url.itemnumber#.jpg">
    <cfset PhotoLocation13 ="#baseurl#/nachos/thumbs/#url.itemnumber#.jpg">
    <cfset PhotoLocation14 ="#baseurl#/pizzas/thumbs/#url.itemnumber#.jpg">
    <cfset PhotoLocation15 ="#baseurl#/popcorn_machines/thumbs/#url.itemnumber#.jpg">
    <cfset PhotoLocation16 ="#baseurl#/popcorn_supplies/thumbs/#url.itemnumber#.jpg">
    <cfset PhotoLocation17 ="#baseurl#/posters/thumbs/#url.itemnumber#.jpg">
    <cfset PhotoLocation18 ="#baseurl#/pretzels/thumbs/#url.itemnumber#.jpg">
    <cfset PhotoLocation19 ="#baseurl#/smoothies___frusheez/thumbs/#url.itemnumber#.jpg">
    <cfset PhotoLocation20 ="#baseurl#/sno-kones__shave_ice/thumbs/#url.itemnumber#.jpg">
<div align="center">
<!--  <cfloop index="i" from="1" to="20" step="1"> -->
<cfset PhotoLocal = #Evaluate(PhotoLocation(i))#>
   <cfif FileExists(PhotoLocal)>
     <img src="#PhotoLocal#">
    <cfelse>
     #PhotoLocal#<br>
    </cfif>
<!--  </cfloop> -->
     </div>
</cfoutput>


Can anyone see why this code gives me a PhotoLocation is undefined error?

    This topic has been closed for replies.

    1 reply

    ilssac
    Inspiring
    May 5, 2010

    <cfset PhotoLocal = #Evaluate(PhotoLocation(i))#>

    This line is trying to evaluate the results of a call to a function named PhotoLocation which does not exist.

    What you where probably trying to write would have been this:

    <cfset PhotoLocal = Evaluate("PhotoLocation#i#")>

    But the better way would have been to use array notation:

    <cfset PhotoLocal = variables["PhotoLocation" & i]>

    OR

    <cfset phtotLocal = variables["PhotoLocation#i#"]>

    I prefer the former version.

    May 5, 2010

    Ian thanks or the heads up but this logic:

    <cfloop index="i" from="1" to="20" step="1">
    <cfset PhotoLocal = variables["PhotoLocation" & i]>
       <cfif FileExists(PhotoLocal)>
         <img src="#PhotoLocal#">
        <cfelse>
         #PhotoLocal#<br>
        </cfif>
    </cfloop>

    Still doesn't show me the picture when the link exists, I know the file is there because I copied the link it showed me and it was there whne I pasted it into my browser.  Thoughts?

    Inspiring
    May 5, 2010
      <cfif FileExists(PhotoLocal)>

         <img src="#PhotoLocal#">

    Well... fileExists() takes a file system path, and an <img/> tag's SRC attribute takes a URL.  So it's not valid to be using the same variable for both.  I presume you are giving a URL in both.  You might want to try expandPath() in your fileExists() call.

    --

    Adam