problem using cfinclude, image paths and CF Admin mappings

Posted on 2009-04-03
Last Modified: 2013-12-16
I'm using cfinclude tags. However, the image links are broken when the pages sit in different level folders.  I have used the mapping in the Coldfusion administrator but the images are still broken.  Here is what I have:

In the CF admin mappings:
Logical Path: /include
Directory Path: C:\Inetpub\wwwroot\intranet2\include  

The include tag:
<cfinclude template="/include/include_rightnav.cfm">
is in the following file:

The include file is located in the following path:

The image tag inside the above include file (/include/include_rightnav.cfm):
<img src="images/UCTV16-sm.gif"  />
is located in the following path:

When I look at the source file in IE this is how the image path is rendered:
<img src="images/UCTV16-sm.gif"/>

Can anyone tell me what I'm doing wrong?? I would very much appreciate it.  I have searched the knowledge base and what I've found is basically what I've done above.

Question by:weharlow
  • 5
  • 4
  • 2
  • +1
LVL 19

Expert Comment

ID: 24059552
make sure that the image is in there

Author Comment

ID: 24059648
The image is definitely in there.
LVL 19

Expert Comment

ID: 24059700
try not to use mapping but access the file with absolute path

Author Comment

ID: 24059823
I'm trying to avoid doing that.  I use dreamweaver and I let it set the path so I don't have to manually type in the path.  In dreamweaver if I choose to set  it to Site Root then it puts the localhost root in the image tag which is incorrect once I upload it to the server.
LVL 39

Expert Comment

ID: 24063195
no you do not want to use the absolute path, unless for a few minutes to test.

try adding / before images as in..

<img src="/images/UCTV16-sm.gif"/>

LVL 39

Expert Comment

ID: 24063218
Since you are referrings the image as  src="images/..."

that means the folder images needs to be directly under whatever folder you're currently in.
But the images folder is not under your current folder, it's under the root folder.
So to reference back to the root, use the leading /   then the folder path will start at the root not in your current location
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


Expert Comment

ID: 24071583
Basically, CF Server and IE have different ideas about "relative" and "absolute" paths.

IE: relative is refering to the current URL that the browser is rendering.
     absolute is referencing the site root.

CF: relative is refering to the current template being processed ... not the one that was called by the browser initially, but the current template.
     absolute is referencing the location on the filestructure of the machine (in your case, c:\wwwroot\intranet2\... or those defined in custom mappings in the CF administrator. (such as mapping /include to mean c:\wwwroot\intranet2\include )

However, non-CFM files will not be included in a custom mapping, since IIS/Apache does not ask CF to handle any non-CFM files, it just hands files out as requested by the browser, so virtual mappings set in CF will not affect these requests.

If you are using images that are site-wide (such as part of the page layout, company logo etc, then place them in a standard folder /images which will resolve to c:\wwwroot\intranet2\images, and always reference them as <IMG SRC="/images/...
If you are using images that are specific to a single page, you have the option of keeping them relative to the page (same folder as the index.cfm the browser requested) or place them in a single site-wide folder /images (c:\wwwroot\intranet2\images\...)

Author Comment

ID: 24077345
Thanks, everyone.  But, I'm just not getting something right.  In addition to what I wrote in my initial question, I've now mapped the image folder as follows:

Logical Path: /images
Directory Path: C:\Inetpub\wwwroot\intranet2\images

And I've changed my image tag to: <img src="/images/UCTV16-sm.gif"  /> and the image link is still broken.  (BTW, I tried this path without mapping too and it did not work.)

Right now I'm using a workaround that I found on by someone named "lovewebdev."  In my application.cfm file I've created a variable <cfset ccpath = "http://localhost/intranet2"> and then added it to the image path in my include file.  <img src="<cfoutput>#ccpath#</cfoutput>/images/UCTV16-sm.gif"/>.  This is not ideal, but will work okay since I don't have to change images and links often in these include files.  When I move it over to the intranet server I just have to change the path in the application.cfm file.
LVL 39

Accepted Solution

gdemaria earned 500 total points
ID: 24077485
what is your root ?

We were assuming your root is wwwroot/intranet2/   but it seems that your root may be wwwroot ?


What you're doing with the cfpath is creating an absolute path to your images.   That's not the best method, as you said.  If you ever have SSL on the site, these images will not be protected and the user will always be prompted "Do you want to show unprotected objects?"

Where did you do this mapping?
>Logical Path: /images
>Directory Path: C:\Inetpub\wwwroot\intranet2\images

I suspect you did it in Coldfusion.   Coldfusion mappings are used for server side instructions such as CFINCLUDE and paths to CFC and such.   By the time your IMG tag gets to the browser, coldfusion is no longer being used and the mapping is not applicable.   You should remove it.

Its important that your web server in production is at the same level as the one in development.  That is,  what is the root of each server?   You want to be sure they are the same level.   We thought /images folder is at your web site root, is it?


Author Comment

ID: 24077732
Aha!  That's the ticket, gdemaria!  wwwroot is my root folder.  I thought I had to map down to the folder the include sits in.  So, I took the mapping out to the images folder, I changed the mapping from /include to /intranet2, added /intranet2 to my img src (src="/intranet2/images/UCTV16-sm.gif") and my include path (<cfinclude template="/intranet2/include/include_rightnav.cfm">) and it works!!

LVL 39

Expert Comment

ID: 24077810
rendering images to the screen is a web-thing, not coldfusion, so your images (as well as javascripts, and style sheets) are all relative to your web structure (not relative to the place where your coldfusion files are located).   Coldfusion file location is really only applicable when using cfinclude and cfc mappings and such.

But why is your root wwwroot and not intranet2 ?   Seems like you may have intranet1 and perhaps intranet3... arent' they all seperate web sites needing their own root ?


Author Comment

ID: 24078075
I only have one intranet and I'm redesiging it.  On my localhost, the intranet sits right on wwwroot because I don't develop any other web sites locally.  So, instead of creating 2 separate sites I just created a separate folder (intranet2) to hold the redesigned pages.  Obviously not good form (this issue being a good example).   The live server does have two sites so I will have to change the mapping accordingly.   I'll match the localhost and live server.  I've just never had an issue with it before probably because I've never used include files this extensively.

Thanks again!

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: : Open Page or Post…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: : Go t…

744 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

8 Experts available now in Live!

Get 1:1 Help Now