# CFFILE ACTION="Write"

You can use the CFFILE tag to write a text file based on dynamic content. For example, you could create static HTML files from this content or log actions in a text file.

### Syntax

    <CFFILE ACTION="Write"
        FILE="full_path_name"
        OUTPUT="content"
        MODE="permission"
        ADDNEWLINE="Yes/No"
        ATTRIBUTES="file_attributes">

#### FILE

Required. The full path name of the file to be created.

#### OUTPUT

Required. The content of the file to be created.

#### MODE

Optional. Defines permissions for a file on Solaris or HP-UX. Ignored in Windows. Valid entries correspond to the octal values (not symbolic) of the Unix chmod command. Permissions are assigned for owner, group, and other, respectively. For example:

    MODE=644

Assigns the owner read/write permissions and group/other read permission.

    MODE=666

Assigns read/write permissions for owner, group, and other.

    MODE=777

Assigns read, write, and execute permissions for all.

#### ADDNEWLINE

Optional. Yes or No. If this attribute is set to Yes, a new line character is appended to the text that is written to the file. If this attribute is set to No, no new line character is appended to the text. The default value is Yes.

#### ATTRIBUTES

Optional. A comma-delimited list of file attributes to be set on the file being written. The following file attributes are supported:

- ReadOnly
- Temporary
- Archive
- Hidden
- System
- Normal

If ATTRIBUTES is not used, the file's attributes are maintained. If Normal is specified as well as any other attributes, Normal is overridden by whatever other attribute is specified.

Individual attributes must be specified explicitly. For example, if you specify just the ReadOnly attribute, all other existing attributes are overwritten.

### Example

The following example creates a file with the information a user entered into an HTML insert form:

    <CFFILE ACTION="Write"
        FILE="c:\files\updates\#Form.UpdateTitle#.txt"
        OUTPUT="Created By: #Form.FullName#
        Date: #Form.Date#
        #Form.Content#">

If the user submitted a form where:

    UpdateTitle="FieldWork"
    FullName="World B. Frueh"
    Date="10/30/98"
    Content="We had a wonderful time in Cambridgeport."

ColdFusion would create a file named FieldWork.txt in the `c:\files\updates\` directory and the file would contain the text:

    Created By: World B. Frueh
    Date: 10/30/98
    We had a wonderful time in Cambridgeport.

This following examples show the use of the MODE attribute for UNIX. The first, creates the file `/tmp/foo` with permissions defined as `rw-r--r--` (owner=read/write, group/other=read).

    <CFFILE ACTION="Write"
        FILE="/tmp/foo"
        MODE=644>

This example appends to the specified file and makes permissions read/write (rw) for all.

    <CFFILE ACTION="Append"
        DESTINATION="/home/tomj/testing.txt"
        MODE=666
        OUTPUT="Is this a test?">

The next example uploads a file and gives it `rwx-rw-rw` permissions (owner/group/other=read/write).

    CFFILE ACTION="Upload"
        FILEFIELD="fieldname"
        DESTINATION="/tmp/program.exe"
        MODE=755>