Retrieving a report stored on disk

63 views Asked by At

I have a report stored as an .cfm file. I have been able to retrieve it fine with a cffile read. Now I want the option of retrieving only part of the report, say the first 50 lines. I decided to try a fileReadLine():

<cfset repname = url['rep']>
<cfset type = url['type']>

<cfset dataFile = fileOpen("/var/www/reports/moxrep/#repname#.cfm", "read" ) >
<cfset i = 0>
<cfoutput>
<cfloop 
condition = "NOT FileIsEOF(dataFile) AND i LT 100">
<cfset i = i + 1>
<cfset inf = fileReadLine( dataFile ) > 
 #inf#
</cfloop>
</cfoutput>
<cfset fileClose( dataFile ) >  

It did not retrieve things at all correctly. The formatting was messed up. All the dynamic data in the report was missing. The CSS links did not operate. And there were many extra blank lines.

Am I doing something wrong? Or is fileReadLine just not meant for retrieving a formatted report? And if not, is there any way to retrieve just part of the report with cffile?

2

There are 2 answers

2
Dale Fraser On

Use cfhttp to get the report, then take that result and strip it down to what you need.

5
Eccountable On

I am not sure you realize that the FileOpen() function is actually reading the raw CFML template and not actually executing the queries that populate your report. Using the CFHTTP tag is definitely a better approach, but be careful because your rendered page is likely to contain all your CSS that would be necessary for the report to render properly so use View Source on your report to see if you want just 50 lines.

The question burning in my mind is "why" do you want just 50 lines? are you previewing the report? it is only 1 page long? Are you embedding it into a dashboard? You may want to consider modifying the .cfm "report" so that the area you want to display elsewhere is wrapped with a specific tag (such as a Span or even something custom) and then when you fetch the report using CFHTTP, then you can parse the results with XMLParse() function (assuming it is properly formatted) and render the section of the report you actually want.