Solved

COLDFUSION - testing to see if file exists

Posted on 2014-04-25
2
1,968 Views
Last Modified: 2014-04-25
I have a directory of images which also contains the cfml page that utilizes those images to populate a vertical scroller. Images and cfml are at the same level in the directory.

The scroller is implemented within the cfml page as follows (extract of code):

<div class="liknoscroller_item" style="display: none;"><img src="image6.jpg" />
<!-- See the "Item Info" tab for the displayed text "caption"  -->
</div>
<div class="liknoscroller_item" style="display: none;"><img src="image7.jpg" />
<!-- See the "Item Info" tab for the displayed text "caption"  -->
</div>
<div class="liknoscroller_item" style="display: none;"><img src="image8.jpg" />
<!-- See the "Item Info" tab for the displayed text "caption"  -->
</div>

 
(above is an 3 line extract of the code supporting the 10 images - image1.jpg..... image10.jpg)




Everything works correctly - provided the user has uploaded all 10 images.

However, if he has only uploaded 9 of the 10 images then the image scroller shows the broken image symbol for that image.

I need a test to determine if an image is missing and then a related action using <cfif > so that the line with the missing image is skipped and is ignored by the scroller.

I have tried the following approach utilizing fileexists, but it does not work. In the example below, the line gets ignored - regardless whether the image3.jpg exists or not.

<cfif FileExists("image3.jpg")>
<div class="liknoscroller_item" style="display: none;"><img src="image3.jpg" />
<!-- See the "Item Info" tab for the displayed text "caption"  -->
       </div></cfif>

Appreciate if someone can take a look and let me know my stupid mistake or recommend an alternative approach
0
Comment
Question by:jameskane
[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 500 total points
ID: 40022486
> <cfif FileExists("image3.jpg")>
It needs to be an absolute path. Try that and you should get the correct results.

    <cfif FileExists( "c:\full\path\to\/webdir\yourImages\image3.jpg" )>

You can also use expandPath with a relative URL:

    <cfif FileExists(  ExpandPath("/webdir/yourImages/image3.jpg") )>
0
 

Author Closing Comment

by:jameskane
ID: 40023196
Perfect. The ExpandPath was the answer.

Thanks again

Jim
0

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

622 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