Server Time:
Monday May 12 2008 07:14 AM  
Your Time:
  
HostMySite.Com is sponsoring this tutorial, please visit their site today!
This tutorial is sponsored by HostMySite.Com - ColdFusion Hosting

Automatically Determine URL and File Path of Application
by: Peter Coppinger
Email this tutorial to a friend Display Printer Friendly Format
[Download in PDF Format] [Download in FlashPaper Format]

<!---

  A handy timesaver:
  Place this in your application.cfm file and you will always know the URL and file path to the root of your application.

  Advanced:
  If for some reason, you need to reset, simply pass is "?flush=1" on any site page

--->



<!--- START: Define Global Settings that should only be set-up once --->
<cfif (NOT isdefined("APPLICATION.siteURL")) OR isdefined("URL.flush")>

   <!--- START: Lock so we can define all application variables safely --->
   <cflock scope="APPLICATION" timeout="#CreateTimeSpan(0,0,0,500)#">

       <cfset APPLICATION.siteURL = replace(GetDirectoryFromPath(
"http://"&cgi.server_name& cgi.path_info),"\","")>
       <cfset APPLICATION.file_path = GetDirectoryFromPath(GetCurrentTemplatePath())>


       <!--- Place other APPLICATION definitions here... --->

    </cflock>
    <!--- END: Lock so we can define all application variables safely --->

</cfif>
<!--- END: Define Global Settings that should only be set-up once --->


Date added: Thu. March 6, 2003
Posted by: Peter Coppinger | Views: 11040 | Tested Platforms: CF4,CF5,CFMX,BlueDragon | Difficulty: Intermediate
Categories Listed: Best Practices

HostMySite.Com is sponsoring this tutorial, please visit their site today!
This tutorial is sponsored by HostMySite.Com - ColdFusion Hosting

Please rate this tutorial:
5 Stars 4 Stars 3 Stars 2 Stars 1 Stars
Comments on this tutorial
Read previous comments on this particular tutorial
cfmx
tried this out today with cfmx, where cgi.path_info returned only an empty string.

After I replaced with cgi.path_info with cgi.script_name I got the correct siteURL
Posted by: thilo
Posted on: 07/27/2004 09:58 AM
CFMX
Couldn't get the siteURL, it show empty, even replaced with cgi.script_name.
Posted by: Jackie
Posted on: 01/14/2005 11:19 PM
works great BUT ..
What if the first file pulled from the site is in a subfolder? I have an admin login area that gets a lot of hits ( more than the public side ), so there is a high likelyhood that by using this method, you could run into problems if you have cfm pages in multiple directories.

I already had errors and found it out the hard way. Be careful here, I am going back to simply calling the function at the time of use

<cfset Destination = GetDirectoryFromPath(GetCurrentTemplatePath()) & "/subdirectory/subfolder/">
Posted by: Michael
Posted on: 02/15/2005 11:32 AM
how to determine subfolders
This is a nice script, but I'm trying to run a slightly more advanced version. I am trying to determine output of a menu based on the subfolder that the page is contained within. However, this script stops once it reaches the root folder. Can you think of how it can determine the last folder to appear (or a more absolute path) and work off of that?
Posted by: Justin
Posted on: 02/28/2008 12:08 PM
Not a problem
Just include from or place this in the application.cfm file.
Posted by: Topper
Posted on: 02/28/2008 06:27 PM
Post a new comment on this tutorial
post a new comment on this particular tutorial
Your Name:
Your Email:
Comment Title:
Comments:
Key Phrase:
 
Skyscrapper Banner Advertisement
ColdFusion Hosting by HostMySite

You are 1 of 693 active sessions! | Privacy | Company
Copyright © 2002 EasyCFM.Com, LLC. (Easy ColdFusion Tutorials) All Rights Reserved
All other trademarks and copyrights are the property of their respective holders.
ColdFusion Hosting ColdFusion Hosting
ADD TO:
Blink
Del.icio.us
Digg
Furl
Google
Simpy
Spurl
Y! MyWeb