cffile action = "write"

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.

Syntax

<cffile 
  action = "write" 
  file = "full_path_name"
  output = "content"
  mode = "permission"
  addNewLine = "Yes" or "No"
  attributes = "file_attributes_list"
  charset = "charset_option" > 

See also

cfdirectory

History

New in ColdFusion MX: on Windows platforms, the attributes attribute values temporary, archive, and system are deprecated. Do not use them in new applications. They might not work, and might cause an error, in later releases.

New in ColdFusion MX: this action attribute option supports the charset attribute.

Attributes

Attribute Req/Opt Default Description
action
Required
 
Type of file manipulation that the tag performs.
file
Required
 
Absolute pathname of file on web server.
On Windows, use backward slashes; on UNIX, use forward slashes.
output
Required
 
Content of the file to be created.
mode
Optional
 
Applies only to Solaris and HP-UX. Permissions. Octal values of Unix chmod command. Assigned to owner, group, and other, respectively. For example:
  • 644: Assigns read/write permission to owner; read permission to group and other
  • 777: Assigns read/write/execute permission to all
addNewLine
Optional
Yes
  • Yes: appends newline character to text written to file
  • No
attributes
Optional
 
One attribute (Windows) or a comma-delimited list of attributes (other platforms) to set on the file.
If omitted, the file's attributes are maintained.
Each value must be specified explicitly. For example, if you specify attributes = "readOnly", all other attributes are overwritten.
  • readOnly
  • hidden
  • normal
charset
Optional
UTF-8
The Java character set name used for the file contents.
The following values are typically used:
  • UTF-8
  • ISO-8859-1
  • UTF-16
  • US-ASCII
  • UTF-16BE
  • UTF-16LE
For a list of character sets, see:
http://www.w3.org/International/O-charset-lang.html

Example

This example creates a file with information a user entered in 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 with the following:

UpdateTitle = "FieldWork"
FullName = "World B. Frueh" 
Date = "10/30/01" 
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 following text:

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

This example shows the use of the mode attribute for UNIX. It creates the file /tmp/foo with permissions rw-r--r-- (owner = read/write, group = read, other = read):

<cffile action = "write"
  file = "/tmp/foo" 
mode = 644> 

This example appends to the file and sets permissions to read/write (rw) for all:

<cffile action = "append"
  destination = "/home/tomj/testing.txt" 
mode = 666 
output = "Is this a test?">

This example uploads a file and gives it the permissions owner/group/other = read/write/execute):

cffile action = "upload"
  fileField = "fieldname" 
destination = "/tmp/program.exe" 
mode = 777>

Comments