• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Is it really there?

LEGEND ,
Aug 17, 2006 Aug 17, 2006

Copy link to clipboard

Copied

I am working on a web site where the original developer set the photos of
students to be dynamic based on their student id number. When their photo is
taken, it gets assigned the student id number, so it can be referenced, and
put into a student photo directory.

however, if the photo does not exist the area comes up with the missing
photo 'x'. Is there a way to find out if the photo actually exists and, if
not, put a alternate image in its place using cfif or another evaluation cf
tag?

Here is the way it is set currently:
<IMG src="../../images/stuPhoto/#Right(People_code_id,9)#.jpg" width="100"
height="100" alt="#first_name# #Last_Name#">

I need to figure out a way to say

<cfif photo exists>
<IMG src="../../images/stuPhoto/#Right(People_code_id,9)#.jpg" width="100"
height="100" alt="#first_name# #Last_Name#">
<cfelse>
<IMG src="../../images/stuPhoto/#nophoto.jpg" width="100" height="100"
alt="#first_name# #Last_Name#">
</cfif>


TOPICS
Advanced techniques

Views

522

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 17, 2006 Aug 17, 2006

Copy link to clipboard

Copied

Just remember this is not the most performant code. If your load is not
to heavy it should be ok. But this does require a file access operation
every time one of these images is to be displayed.

<cfif FileExists(file.path.to.image)>
<img show Image>
<cfelse>
<img default image>
</cfif>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 17, 2006 Aug 17, 2006

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 17, 2006 Aug 17, 2006

Copy link to clipboard

Copied

Getting closer. Thanks for the direction.

What is wrong with this?
<cfset yourphoto=#Right(People_code_id,9)#.jpg)>


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 17, 2006 Aug 17, 2006

Copy link to clipboard

Copied

Opps:
<cfset yourphoto=#Right(People_code_id,9)#.jpg

Getting:
a cfset tag beginning on line 99, column 34.


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 17, 2006 Aug 17, 2006

Copy link to clipboard

Copied

<cfset yourphoto=#Right(People_code_id,9)#.jpg>


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 17, 2006 Aug 17, 2006

Copy link to clipboard

Copied

<cfset yourphoto=#Right(People_code_id,9)#.jpg>

You either need quotes our concatenation.

<cfset yourphoto = "#right(People_code_id,9)#.jpg">
OR
<cfset yourphoto = right(People_code_id,9) & ".jpg">

If you can give me an example of what People_code_id looks like, there
may be clear ways to get the number out of it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 17, 2006 Aug 17, 2006

Copy link to clipboard

Copied

Ok, that worked like a charm, but now I am having problems with the original
question. I have this:

<cfset yourphoto = right(People_code_id,9) & ".jpg">
<cfif FileExists(ExpandPath(yourphoto))>
<IMG src="../../images/stuPhoto/#yourphoto#" width="100" height="100"
alt="#first_name# #Last_Name#">
<cfelse>
<IMG src="../../images/stuPhoto/nophoto.jpg" width="100" height="100"
alt="#first_name# #Last_Name#">
</cfif>

I outputted the 'yourphoto' and it sets the yourphoto to the correct .jpg
name, but it keeps showing the second 'nophoto.jpg' regardless if its there
or not.

Any ideas?


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 17, 2006 Aug 17, 2006

Copy link to clipboard

Copied

Output what ExpandPath(yourphoto) is returning.

My guess is it's not pointing to the right place.

You're going to want:
ExpandPath("../../images/stuPhoto/#yourphoto#")

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 17, 2006 Aug 17, 2006

Copy link to clipboard

Copied

I changed it to:

<cfset yourphoto = right(People_code_id,9) & ".jpg">
<cfif FileExists("../../images/stuPhoto/#yourphoto#")>
<IMG src="../../images/stuPhoto/#yourphoto#" width="100" height="100"
alt="#first_name# #Last_Name#">
<cfelse>
<IMG src="../../images/stuPhoto/nophoto.jpg" width="100" height="100"
alt="#first_name# #Last_Name#">
</cfif>

but it still always comes up with the nophoto.jpg


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 17, 2006 Aug 17, 2006

Copy link to clipboard

Copied

LATEST
Wally,

Please read what I posted.

"Output what ExpandPath(yourphoto) is returning.

My guess is it's not pointing to the right place.

You're going to want:
ExpandPath("../../images/stuPhoto/#yourphoto#")"

I didn't tell you to change the FileExists to contain the path.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 17, 2006 Aug 17, 2006

Copy link to clipboard

Copied

Output ExpandPath(yourPhoto) and see if you are getting what you are
expecting.

In the MX era of ColdFusion, there may be two directories that can
server up files for applications depending on how ColdFusion was
configured. The wwwroot, e.g. c:/inetpub/wwwroot, and the ColdFusion
root, e.g. c:/cfusion/wwwroot or
c:/jrun4/servers/cfusion/cfusion-ear/cfusion-war/.

IIRC the expand path will return the ColdFusion root. If this is the
case you may want to play with some of the other System Functions such
as GetBaseTemplatePath() or Get CurrentTemplatePath() in conjunction
with the getDirectoryFromPath() function.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 17, 2006 Aug 17, 2006

Copy link to clipboard

Copied

<cfif FileExists("../../images/stuPhoto/#yourphoto#")>

That is a url path. FileExists() needs a system path. Something like
FileExists("c://inetpub/wwwroot/images/stuPhoto/" & yourPhoto) for a
common Windows webserver configuration.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation