Solved

COLDFUSION - testing to see if file exists

Posted on 2014-04-25
2
1,600 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
2 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
Comment Utility
> <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
Comment Utility
Perfect. The ExpandPath was the answer.

Thanks again

Jim
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now