cffile

Manages interactions with server files.
Different combinations cause different attributes to be
required.

 <cffile action="read">

 fileRead(path);

cffile Attribute Reference

action
Required

Type of file manipulation that the tag performs. Values:
  • append
  • copy
  • delete
  • move
  • read
  • readbinary
  • rename
  • upload
  • uploadall
  • write

file

Pathname of the file.

mode

Applies only to UNIX and Linux. Permissions. Octal values
of Unix chmod command. Assigned to owner, group, and
other, respectively.

output

String to add to the file

addnewline
Default: YES

Yes: appends newline character to text written to file

attributes

Applies to Windows. A comma-delimited list of attributes
to set on the file.

If omitted, the file's attributes are maintained. Values:
  • readonly
  • hidden
  • normal
  • system
  • temporary

charset

The character encoding in which the file contents is
encoded.

For more information on character encodings, see:
www.w3.org/International/O-charset.html. Values:
  • utf-8
  • iso-8859-1
  • windows-1252
  • us-ascii
  • shift_jis
  • iso-2022-jp
  • euc-jp
  • euc-kr
  • big5
  • euc-cn
  • utf-16

source

Pathname of the file (during copy).

destination

Pathname of a directory or file on web server
(during copy).

variable

Name of variable to contain contents of text file.

filefield

Name of form field used to select the file.

Do not use pound signs (#) to specify the field name.

nameconflict

Action to take if filename is the same as that of a file
in the directory. Values:
  • error
  • skip
  • overwrite
  • makeunique

accept

Limits the MIME types to accept. Comma-delimited list. For
example, to permit JPG and Microsoft Word file uploads:

accept = "image/jpg, application/msword"

result
Default: cffile

Allows you to specify a name for the variable in which cffile
returns the result (or status) parameters. If you do not specify
a value for this attribute, cffile uses the prefix "cffile".

fixnewline
Default: NO

* Yes: changes embedded line-ending characters in string
variables to operating-system specific line endings
* No: (default) do not change embedded line-ending
characters in string variables.

Examples sample code using the cffile tag


Script Syntax

File Write

fileWrite(expandPath("./myFile.txt"), "Here's some content for my file.");

Script Syntax

File Append - There is no fileAppend() so we access the file and use fileWriteLine()

myFile = fileOpen(expandPath("./myFile.txt"), "write"); 
 fileWriteLine(myFile, "Here's some new content."); 
 fileClose(myFile);

Script Syntax

File Read

myFile = fileRead(expandPath("./myFile.txt"));

Script Syntax

File Read Binary

myImageBinary = fileReadBinary(expandPath("./myImage.jpg"));

Script Syntax

File Rename - Since there is no fileRename(), fileMove() works just as well

fileMove(expandPath("./myFile.txt"), expandPath("./myNewFileName.txt"));

Script Syntax

File Copy

fileCopy(expandPath("./myFile.txt"), expandPath("./some/other/path"));

Script Syntax

File Move

fileMove(expandPath("./myFile.txt"), expandPath("./some/other/path"));

Script Syntax

File Delete

fileDelete(expandPath("./myFile.txt"));

Script Syntax

File Upload

fileUpload(expandPath("./destination"), "form.myFile", " ", "makeunique");

Script Syntax

File Upload All

fileUploadAll(expandPath("./destination"), " ", "makeunique");

Tag Syntax

File Write

<cffile action="write" file="#expandPath("./myFile.txt")#" output="Here's some content for my file.">

Tag Syntax

File Append

<cffile action="append" file="#expandPath("./myFile.txt")#" attributes="normal" output="Here's some new content.">

Tag Syntax

File Read

<cffile action="read" file="#expandPath("./myFile.txt")#" variable="myFile">

Tag Syntax

File Read Binary

<cffile action="readBinary" file="#expandPath("./myImage.jpg")#" variable="myImageBinary">

Tag Syntax

File Rename

<cffile action="rename" source="#expandPath("./myFile.txt")#" destination="#expandPath("./myNewFileName.txt")#" attributes="normal">

Tag Syntax

File Copy

<cffile action="copy" source="#expandPath("./myFile.txt")#" destination="#expandPath("./some/other/path")#">

Tag Syntax

File Move

<cffile action="move" source="#expandPath("./myFile.txt")#" destination="#expandPath("./some/other/path")#">

Tag Syntax

File Delete

<cffile action="delete" file="#expandPath("./myFile.txt")#">

Tag Syntax

File Upload

<cffile action="upload" destination="#expandPath("./destination)#" filefield="form.myFile" nameconflict="makeunique">

Tag Syntax

File Upload All

<cffile action="uploadall" destination="#expandPath("./destination")#" nameconflict="makeunique">

Fork me on GitHub