If the webapp root and the web root are the same then what you have will
work: in HTTP/HTML beginning an address with a slash says "go to the web
root, then down".  In other words <img src="" will
search for the "images" folder off of the webroot.

The simplest way to what you want if they're different is to set a server
mapping: say "/images" is actually
"d:/webroot/materials/stuff/things/images" (or whatever.  You would also
have to set a ColdFusion mapping if you want to access CustomTags or
Includes via the alias.

Completely in ColdFusion you could use the various path functions to figure
this out, but you'd need a variable in your path.  I do this kind of thing
(in MX) via a cached CFC.  I pass it an "WebRootOffset" argument which is
the current application's offset from the web root (for example my site is
in webroot/depressedpress/ so the offset is /depressedpress )

If I instantiate from Application.cfm it's easy to automate the process.

Once that's done The CFC is cached in the Application scope as
"Application.DP.Paths".  Then I have a request CFC that, when it gets
instantiated, sets up following request-specific variables using the paths
CFCs methods:

<cfset this.RelFromWebRoot =
this.DP_Application.Paths.GetRelFromWebRoot(arguments.Path) />

<cfset this.RelToWebRoot =
this.DP_Application.Paths.GetRelToWebRoot(arguments.Path) />

<cfset this.RelFromAppRoot =
this.DP_Application.Paths.GetRelFromAppRoot(arguments.Path) />

<cfset this.RelToAppRoot =
this.DP_Application.Paths.GetRelToAppRoot(arguments.Path) />

<cfset this.SysToTemplate =
this.DP_Application.Paths.GetSysToTemplate(arguments.Path) />

To set up an "images" variable for use by anything in the request you could
then do

<cfset this.ImagesPath = this.RelToAppRoot & "images/"  />

Of course you need to store this someplace and use the Request scope (any
particular reason you can't)?  You could instantiate the paths CFC in the
application scope only and use it from there I suppose.

So to use it in an image tag you would then do (inside a CFOUTPUT):

<img src="">
If the rest of the process was followed then this would find the image - and
it would continue to find it even if you move the application to another
folder.

I could send you the CFC if you'd like.

Jim Davis



From: CF Developer [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 22, 2004 10:40 AM
To: CF-Talk
Subject: webroot level?

i know there is a way, just not coming to mind.

what I want to be able to do is specify the root level of an application
w/o having to set a request variable.

such as:
request.images = "images/"

or if i am one folder down:
request.images = "../images/"

isn't there a way to specify something like:

img src="">
and it point to the root of the web app regardless of how many folders
down you are within the application???
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to