Description:-

Writes a text file on the server, based on dynamic content. You can create static HTML files from the content, or log actions in a text file.

<cffile
    action = "write"
    file = "full pathname"
    output = "content"
    addNewLine = "yes|no"
    attributes = "file attributes list"
    charset = "character set option"
    fixnewline = "yes|no"
    mode = "permission"
>

Attributes:-

action:- This is a required argument for the type of file manipulation the tag performs.

file:- This is a required attribute, The pathname of the file to which to write the content.

output:- This is a required attribute and the content of the file is to be created.

addNewLine:- This is a non-required attribute, the default value is yes.

attributes:- This is a non-required attribute, A comma-delimited list of attributes to set on the file that applies to Windows. the values are:-
readOnly
hidden
normal

charset:- This is a non-required attribute, JVM default file character set for the default value, The character encoding in which the file contents are encoded. The following list includes commonly used values:-
utf-8
iso-8859-1
windows-1252
us-ascii
shift_jis
iso-2022-jp
euc-jp
euc-kr
big5
euc-cn
utf-16

fixnewline:- This is a non-required attribute, the default value is no.

mode:- This is a non-required attribute and applies only to UNIX and Linux. Permissions. Octal values of UNIX chmod command. Assigned to owner, group, and other, respectively.
644:- assigns read/write permission to the owner; read permission to group and others.
777:- assigns read/write/execute permission to all.

Example:-

This example creates a file with information a user entered in an HTML insert form:

<cffile
    action = "write"
    file = "d:\files\documents\#form.updateTitle#.txt"
    output = "Created By: #form.fullName#, Date: #form.date#, Content: #form.content#"
>

If the user submitted a form with the following:

updateTitle = "testNote"
fullName = "Test Note File"
date = "12/21/24"
content = "We create a test content."

ColdFusion would create a file named testNote.txt in the d:\files\documents\ directory and the file would contain the following text:

Created By: Test Note File,
Date: 12/21/24,
We create a test content.