Go Premium for a chance to win a PS4. Enter to Win


problem using cfinclude, image paths and CF Admin mappings

Posted on 2009-04-03
Medium Priority
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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.


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

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 dreamweaverforum.info 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 2000 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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

886 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