Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

get file name/path of current .cfm file...

New Here ,
Nov 01, 2009 Nov 01, 2009

i am going to make a "tracking" script for a website.  my idea is to add a <CFINCLUDE> to every .cfm file on the server (right at the end, so it would be easier to remove when im done), and have the script that is included add a record to a database that contains the file name/path of the .cfm file.  for example, index.cfm will include trackscript.cfm, and after the index.cfm is processed, a database will have a record in it containing the file name/path for index.cfm.

i am new to coldfusion, but i think i have everything figured out, except how to get the name of the file that will be added to the database.  is there some kind of function or variable available that will give me the filename of the currently executing .cfm file?

3.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 02, 2009 Nov 02, 2009
GetCurrentTemplatePath() will give you the absolute path of the current CFM file.
Translate
LEGEND ,
Nov 01, 2009 Nov 01, 2009

I don't think sticking a <cfinclude> call into every file is really a very good way of doing this.

You should have a look at using onRequestEnd() for this sort of thing.

There are various variables in the CGI scope which one can use to build the originating URL of the current request; CGI.script_name and CGI.query_string are probably the most helpful here.  One can resolve the underlying file system path form a URL using expandPath().

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 01, 2009 Nov 01, 2009

i was thinking about using a cfinclude because i could just write one script, and just link to that script from each file (keeping everything cleaner), rather than inserting all of the code into each individual file.

something i should point out: i'm not needing this as a tracking system to be used daily on the site.  we have an expansive site, and over time, there are a lot of files sitting on the server that we don't need (like temporary edits and whatnot).  so, i was thinking that if i made a quick tracking script to log which pages are actually accessed, and then use something like a website downloader (an app for offline browsing), the tracking script would give us a pretty good idea of what files are actually used, and then what files cannot even be accessed via normal browsing of the site.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 02, 2009 Nov 02, 2009

Yep, I understand what you're trying to do, but I don't think it's a very good approach.

Have a look at how the debugging service can give you access to all the templates used in a request - in one fell swoop - by looking @ the code in [coldfusion context root]/WEB-INF/debug/classic.cfm.

You could either use that technique in onRequestEnd(), or perhaps better now that I think about it, just modify your debug template to write the list of templates to your DB.

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 02, 2009 Nov 02, 2009
LATEST
GetCurrentTemplatePath() will give you the absolute path of the current CFM file.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources