Skip to main content
Inspiring
March 26, 2009
Question

finding image with relative path

  • March 26, 2009
  • 1 reply
  • 363 views
I don't know why this is throwing me, but it's been a long day and I am probably not thinking clearly.

I am setting up a new simple site to use as an example for others. My Aplication.cfc file includes my header page in the OnRequestStart method. The Application.cfc file is in my root. Any .cfm page located in the root has no problem seeing the header and its images.

Ant page located in a subfolder below the root can't find any of the images on the header page. Any text on the header page is displayed correctly, but images aren't shown

--------------Application.cfc--------------------
<cfcomponent displayname="Application" output="true">
<cffunction name="onRequestStart" output="true" returntype="boolean">
<cfinclude template="../headfoot/wcfHeader.cfm">
<cfreturn true>
</cffunction>
</cfcomponent>
------------------------------------------------------
-------------wcfHeader.cfm--------------------
<body >
<img src="images/wsbanner400.jpg" width="400" height="95" alt="WCF banner"/><br />
Some header text.

</body>
------------------------------------------------------


    This topic has been closed for replies.

    1 reply

    Inspiring
    March 27, 2009
    that's because thas is exactly the code that will be in your pages in
    the sub-folder:
    <img src="images/wsbanner400.jpg" width="400" height="95" alt="WCF
    banner"/>
    and your subfolder, obviously, does not have wsbanner400.jpg in an
    'images' sub-folder in it (if it at all has an 'images' sub-folder).

    you should define the source of images in your header/footer included
    files relative to your site's webroot instead of relative to current page:
    <img src="/images/wsbanner400.jpg" width="400" height="95" alt="WCF
    banner"/>

    (note that the src attribute now starts with /, which makes the web
    server look for the image in the specified folder(s) starting from your
    site's root).


    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/