View comments | RSS feed
Contents > CFML Reference > ColdFusion Tags > cffile action = "write" PreviousNext

cffile action = "write"

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_path_name"
output = "content"
mode = "permission"
addNewLine = "Yes" or "No"
attributes = "file_attributes_list"
charset = "charset_option" >

cfdirectory

See the History section of the main cffile tag page.

Attribute

Req/Opt

Default

Description

action

Required

 

Type of file manipulation that the tag performs.

file

Required

 

Pathname of the file to write.

If not an absolute path (starting a with a drive letter and a colon, or a forward or backward slash), it is relative to the ColdFusion temporary directory, which is returned by the GetTempDirectory function.

output

Required

 

Content of the file to be created.

mode

Optional

 

Applies only to UNIX and Linux. 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

 

Applies to Windows. A comma-delimited list of attributes 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

JVM default file character set.

The character encoding in which the file contents is 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

For more information character encodings, see: www.w3.org/International/O-charset.html.

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>

Contents > CFML Reference > ColdFusion Tags > cffile action = "write" PreviousNext

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


methik said on Dec 30, 2004 at 3:34 PM :
Can anyone explain why this works just fine:

<cffile
action="write"
file="\\Server\Inetpub\wwwroot\Alpha\Beta\test.txt"
output="This is a test">

But I get an error "Error: All or part of the path is invalid." when I try to run this:

<cffile
action="write"
file="/Beta/test.txt"
output="This is a test">

Even though the "Alpha" directory is designated as the web root in IIS AND I have defined it as "/" in ColdFusion Administrator's Mappings section. Everything else seems to work just fine, for example:

<a href="/Beta/test.txt">
<img src="/Beta/picture.jpg">
<cfinclude template="/Beta/test.txt">

all work as I would expect them to. Why do cffile and cfdirectory have to be different?
TheoPeters said on Mar 3, 2005 at 8:23 AM :
Because administrative directory mapping apply to web content accessed through cfinclude, cfmodule, urls, etc. CFFILE and CFDIRECTORY are not assumed to be accessing web content, they are assumed to be used on files anywhere on your server, not necessarily in your web tree. This was a decision on Macromedia's (Allaire's) part. Sometimes it will be more convenient, sometimes not.
shahzad said on May 11, 2005 at 12:03 PM :
why isn't the nameconflict option included in the docs? when it does exist

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/tags-p36.htm