Solved

COLDFUSION - testing to see if file exists

Posted on 2014-04-25
2
1,715 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
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Joomla Website Malfunction 9 118
Re-imbursement Claim System 3 71
Server error in 'XXXXXXXX' application. 12 84
Update cached table in H2 database 6 56
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…
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

810 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