• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

Path to an image

Hi,

I have created field in my database to store the path of images and I store all my images in a folder.

what I want to do is when the path to an image exist but the image is not in the folder don't display the image.

how can I say it?

I have this:
<cfif len(SmlPathImage1)>
					<span style="cursor:pointer;"><img src="#SmlPathImage1#" style="border-bottom: 1px solid;border-top: 1px solid;border-right: 1px solid;border-left: 1px solid;" width="70px" height="52px"/></span>
				<cfelseif len(SmlPathImage2)>
					<span style="cursor:pointer;"><img src="#SmlPathImage2#" style="border-bottom: 1px solid;border-top: 1px solid;border-right: 1px solid;border-left: 1px solid;" width="70px" height="52px"/></span>
				<cfelseif len(SmlPathImage3)>
					<span style="cursor:pointer;"><img src="#SmlPathImage3#" style="border-bottom: 1px solid;border-top: 1px solid;border-right: 1px solid;border-left: 1px solid;" width="70px" height="52px"/></span>
				<cfelseif len(SmlPathImage4)>
					<span style="cursor:pointer;"><img src="#SmlPathImage4#" style="border-bottom: 1px solid;border-top: 1px solid;border-right: 1px solid;border-left: 1px solid;" width="70px" height="52px"/></span>
				<cfelse>
				<span style="cursor:pointer;"><img src="images/WhbgNoImage.gif" style="border-bottom: 1px solid;border-top: 1px solid;border-right: 1px solid;border-left: 1px solid;" width="70px" height="52px"/></span>
				</cfif>

Open in new window

0
lulu50
Asked:
lulu50
  • 2
1 Solution
 
PluckaCommented:
<cfif fileExists(filePath)>
    Display image
<cfelse>
    Dont
</cfif>
0
 
gdemariaCommented:
fileExists() is the function to use, but I think you need a bit more.

You should continue to test the len()  as well... that just saves fileExists() from attempting to test an empty path for no reason.

But I think you also need expandPath() .   I assume your path is a relative URL from the root, that is

 SmlPathImage3   may be   "/library/images/doggy.gif"

(I hope you are not using the domain name or http or anything in that variable)

If it is the relative path, you need to expand it using expandPath() so it becomes a directory path...

   c:\inetpub\wwwroot\myApp\library\images\doggy.gif

This is a path you can test with fileExists...


If your variable doesn't hold a relative path, please let us know what it is...

<cfif len(SmlPathImage1) and fileExists(expandPath(SmlPathImage1))>
	<span style="cursor:pointer;"><img src="#SmlPathImage1#" style="border-bottom: 1px solid;border-top: 1px solid;border-right: 1px solid;border-left: 1px solid;" width="70px" height="52px"/></span>
<cfelseif len(SmlPathImage2) and fileExists(expandPath(SmlPathImage2))>
	<span style="cursor:pointer;"><img src="#SmlPathImage2#" style="border-bottom: 1px solid;border-top: 1px solid;border-right: 1px solid;border-left: 1px solid;" width="70px" height="52px"/></span>
<cfelseif len(SmlPathImage3) and fileExists(expandPath(SmlPathImage3))>
	<span style="cursor:pointer;"><img src="#SmlPathImage3#" style="border-bottom: 1px solid;border-top: 1px solid;border-right: 1px solid;border-left: 1px solid;" width="70px" height="52px"/></span>
<cfelseif len(SmlPathImage4) and fileExists(expandPath(SmlPathImage4))>
	<span style="cursor:pointer;"><img src="#SmlPathImage4#" style="border-bottom: 1px solid;border-top: 1px solid;border-right: 1px solid;border-left: 1px solid;" width="70px" height="52px"/></span>
<cfelse>
    <span style="cursor:pointer;"><img src="images/WhbgNoImage.gif" style="border-bottom: 1px solid;border-top: 1px solid;border-right: 1px solid;border-left: 1px solid;" width="70px" height="52px"/></span>
</cfif>

Open in new window

0
 
lulu50Author Commented:

gdemaria:

yes I do have stored relative URL in my database.  

It worked great!!!


0
 
lulu50Author Commented:
Thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now