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

Cfheader and cfcontent question

Participant ,
Mar 10, 2009 Mar 10, 2009

Copy link to clipboard

Copied

Hi Community!

I wrote a program that generates a pipe delimited file

The file downloads to my desktop but I want it to be downloaded to a location in one of my servers. How do I accomplish that?

This is how my cfheader and cfcontent lines of code looks like:

<cfcontent type="text/plain" reset="yes">
<cfheader name="Content-Disposition" charset="utf-8" value="attachment;filename=companyname_#DateFormat(now(),'MMDDYYYYhhmmss')#.txt">

Any thoughts fellows?

Thanks!
TOPICS
Advanced techniques

Views

1.9K

Translate

Translate

Report

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

Participant , Mar 11, 2009 Mar 11, 2009
Adam and Ian:

cffile combined with a cfsavecontent solved my problem!\

Thanks!

Votes

Translate

Translate
LEGEND ,
Mar 10, 2009 Mar 10, 2009

Copy link to clipboard

Copied

Sounds like the wrong tool for the desire job.

<cfcontent...> is for just what it is doing. Delivering content to the
client that requested it. So the file is going to end up there, on the
client system.

If you want to write the file locally on the ColdFusion application
server or to a networked server, the <cffile...> tag is the tag for
this. If you are trying to use networked servers; be aware that, by
default, ColdFusion is configured to only have permissions to its local
server. You will need to configure it to have the desired permissions
to other servers.

If you are trying to get the file to a server that does not share file
system access with the ColdFusion server, <cfftp...> would be the tag to
move the file. This, of course, requires the receiving server to accept
FTP protocol requests.

If you can't write files to this server, ftp to this server or have some
process on this server make a HTTP request to the ColdFusion server,
then you are going to need to find somebody to walk a disk or memory
stick from the ColdFusion server to the receiving server with the file
on it.

Votes

Translate

Translate

Report

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 ,
Mar 10, 2009 Mar 10, 2009

Copy link to clipboard

Copied

If the CF server is on the same network as the server you mention, and it
has permissions to do so, you can just write the file with <cffile>.

If it doesn't have that sort of access, you'll need to use <cfftp> or
something, which would necessitate the server in question to be running as
an FTP server.

What is happening to this file once it arrives at its location on the
server? I presume some other sort of process / application is picking it
up and doing something with it? Can that application request the file
directly from the CF server when it needs it, via a web service call, or
HTTP request?

--
Adam

Votes

Translate

Translate

Report

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 ,
Mar 10, 2009 Mar 10, 2009

Copy link to clipboard

Copied

OK, so the similarity between your post and my post was a bit spooky, Ian.

--
Adam

Votes

Translate

Translate

Report

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 ,
Mar 10, 2009 Mar 10, 2009

Copy link to clipboard

Copied

Adam Cameron wrote:
> OK, so the similarity between your post and my post was a bit spooky, Ian.
>

Great minds...alike and all that.

But to get my quota of gloating in today.

My post was 2 minutes sooner (according my my e-mail time stamps)

And you did not include the sneaker net option! ;-)

Votes

Translate

Translate

Report

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
Participant ,
Mar 10, 2009 Mar 10, 2009

Copy link to clipboard

Copied

Adam and Ian:

Thank you for your posts. It looks to me that I will have to use the cffile tags. I was using cfcontent and cfheader because it was easier for me to add the contents to the txt file.

I extract my fields from a query then pipe delimit them into a txt file.

How would I add that content to the file using cffile?

Votes

Translate

Translate

Report

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
Participant ,
Mar 10, 2009 Mar 10, 2009

Copy link to clipboard

Copied

This is my code to add the content of the generated txt file:

<cfoutput>
<cfloop index="idx" from="1" to="#getFields.recordcount#">
#Trim(getFields.email[idx])#|#Trim(getFields.firstname[idx])#|#Trim(getFields.lastname[idx])#|#Trim(getFields.postalcode[idx])#|#Trim(getFields.campaign[idx])#|#DateFormat(getFields.firstordd[idx],'MM/DD/YYYY hh:mm:ss:l')#|#getFields.firstordamt[idx]#|#DateFormat(getFields.lastordd[idx],'MM/DD/YYYY hh:mm:ss:l')#|#getFields.lastordamt[idx]#|#getFields.htdordcnt[idx]#|#getFields.htdordtot[idx]#|#getFields.annualordcnt[idx]#|#getFields.annualordtot[idx]##Chr(13)##Chr(10)#
<cfset flagList = "">
</cfloop>
</cfoutput>

Votes

Translate

Translate

Report

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
Advisor ,
Mar 10, 2009 Mar 10, 2009

Copy link to clipboard

Copied

Your use of DateFormat does not appear to be correct. For the time portion you will need to add the TimeFormat function.

You might also consider using the date format "yyyymmdd" so that your files will be sorted by date when they are listed by file name order.

See sample.

Votes

Translate

Translate

Report

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 ,
Mar 10, 2009 Mar 10, 2009

Copy link to clipboard

Copied

Instead of outputting the content to the response stream, you generate
it into a variable then use that variable in the appropriate property of
the <cffile...> tag.

<cfsaveContent...> makes this very easy and would not require much
modification to your code, but is by no means the only way to accomplish
this.



Votes

Translate

Translate

Report

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
Participant ,
Mar 10, 2009 Mar 10, 2009

Copy link to clipboard

Copied

I was able to use cfsavecontent but my list of values doesn't read the char(13) character. At the end of each line I want to hit enter. I used cfsavecontent like this:

<cfsavecontent variable="fileContent">
<cfloop index="idx" from="1" to="#getFields.recordcount#">
<cfoutput> #Trim(getFields.email[idx])#|#Trim(getFields.firstname[idx])#|#Trim(getFields.lastname[idx])#|#Trim(getFields.postalcode[idx])#|#Trim(getFields.campaign[idx])#|#DateFormat(getFields.firstordd[idx],'MM/DD/YYYY hh:mm:ss:l')#|#getFields.firstordamt[idx]#|#DateFormat(getFields.lastordd[idx],'MM/DD/YYYY hh:mm:ss:l')#|#getFields.lastordamt[idx]#|#getFields.htdordcnt[idx]#|#getFields.htdordtot[idx]#|#getFields.annualordcnt[idx]#|#getFields.annualordtot[idx]##chr(13)#
</cfoutput>
</cfloop>
</cfsavecontent>

Any thoughts?

Votes

Translate

Translate

Report

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
Advisor ,
Mar 10, 2009 Mar 10, 2009

Copy link to clipboard

Copied

For Windows OS newline is Chr(13) & Chr(10). For Unix Chr(10).

You may also want to remove the white space within your CFSAVECONTENT open and close tags. Any white space within the tags is treated as part of the content to be saved. An HTML file would ignore this white space but it could be important to a formatted text file.

Chr function:
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions_c-d_04.html#4749523

Votes

Translate

Translate

Report

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 ,
Mar 10, 2009 Mar 10, 2009

Copy link to clipboard

Copied

apocalipsis19 wrote:
>
> Any thoughts?
>

Two, right of the top of my head.

One, in the windows world, it is usually a carriage return and a line
feed character (i.e. #chr(13)##chr(10)# at the end of the lines, Unix
traditionally just uses a carriage return.

Second, you are not outputting HTML anymore - which ignores most extra
whitespace in the content. So all the extra whitespace characters
[spaces, tabs, returns etc.] in your content block count and can easily
throw off file formats.

Try this and see if it gets you closer.

<cfoutput>
<!--- outside the content block so it does not get in the way. --->
<cfsavecontent variable="fileContent"><cfloop
...>#var1#|#var2#|#varN##chr(13)##chr(10)#</cfloop></cfsaveContent>
<!--- notice how the <cfsavecontent...> block is on one line --->
</cfoutput>

OR you could also do string concatenation something like this.

<cfset fileContent = "">
<cfloop...>
<cfset fileContent = fileContent & var1 & '|' & var2 & '|' & varN &
chr(13) & chr(10>
</cfloop>

OR

you could use the append file function of the cffile tag.

<cffile action="write" ... output="#firstLineOfData#">
<cfloop...>
<cffile action="append" ... output="#otherLinesOfData#">
</cfloop>

Votes

Translate

Translate

Report

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 ,
Mar 10, 2009 Mar 10, 2009

Copy link to clipboard

Copied

> Adam Cameron wrote:
>> OK, so the similarity between your post and my post was a bit spooky, Ian.
>>
>
> Great minds...alike and all that.
>
> But to get my quota of gloating in today.
>
> My post was 2 minutes sooner (according my my e-mail time stamps)
>
> And you did not include the sneaker net option! ;-)

Heh.

As I've always said (?), "it's the uniform high quality of answer that
really makes these forums great".

[snort]

;-)

--
Adam

Votes

Translate

Translate

Report

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
Participant ,
Mar 11, 2009 Mar 11, 2009

Copy link to clipboard

Copied

LATEST
Adam and Ian:

cffile combined with a cfsavecontent solved my problem!\

Thanks!

Votes

Translate

Translate

Report

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
Documentation