Solved

COLDFUSION - testing to see if file exists

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
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…
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.

685 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