TruthInSatire
Programmer
I asked this question a while back when I was first learning CF transitioning from ASP. I didn't get an answer, but now that I know more about CF I am able to answer it. The question was: "Is there an ASP equivalent function for "server.mapPath()" in ColdFusion?"
The closest thing was expandPath(). The problem with expandpath(), is it begins in the current folder the template resides in... That means you have to know how many levels up or down you need to go. This can be bothersome if you're several levels above or below your desired folder.
Server.mapPath() begins maping from the webs root all the time despite what folder the asp file is in. This is very helpful for code used over and over in different folder levels where files are being manipulated with File system object(ASP) or <cfFile>(CF)
I've been doing allot with <cffile> lately so I decided to revist the issue. I've come up with the following script which could easily be made into a tag if desired.
With all that said if there is an easier or more foolproof way to do this let me know.
in this example the output would* be "c:webspace\ assuming "c:webspace\ is where your website is on the server.
* would could easily be swapped with "should"
Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
The closest thing was expandPath(). The problem with expandpath(), is it begins in the current folder the template resides in... That means you have to know how many levels up or down you need to go. This can be bothersome if you're several levels above or below your desired folder.
Server.mapPath() begins maping from the webs root all the time despite what folder the asp file is in. This is very helpful for code used over and over in different folder levels where files are being manipulated with File system object(ASP) or <cfFile>(CF)
I've been doing allot with <cffile> lately so I decided to revist the issue. I've come up with the following script which could easily be made into a tag if desired.
With all that said if there is an easier or more foolproof way to do this let me know.
Code:
<cfscript>
function mapPath(folder){
siteRoot = mid(cgi.PATH_TRANSLATED, 1, findNoCase(replaceNoCase(cgi.PATH_INFO, "/", "\","All"), cgi.PATH_TRANSLATED));
userPath = siteRoot & replaceNoCase(folder, "/", "\","All");
//return the new path
return (userPath);
}
</cfscript>
<cfoutput>#mapPath("family/images/")#</cfoutput>
* would could easily be swapped with "should"
Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)