Handles all common interactions with files.

The attributes you use with cffile depend on the value of the action attribute.

For example, if the action = "write", use the attributes associated with writing a text file.

This tag may have a body.

This tag is also supported within <cfscript>

<cffile storeacl=object action=info|move|rename|copy|delete|read|readbinary|write|append|upload|uploadall|touch serverpassword=string source=string attributes=string destination=string mode=string filefield=string charset=string nameconflict=string accept=string strict=boolean createpath=boolean file=string variable=string output=any cachedwithin=object addnewline=boolean fixnewline=boolean result=string allowedextensions=any blockedextensions=any ><!--- body --->[</cffile>]
Attribute Description
object, optional

Access Control List (ACL) to use for new files. Can be a either a string ("authenticated-read", "private", "public-read", or "public-read-write"), or an array of structs where each struct represents a permission or grant.

Example: [{email="xxx@yyy.com", permission="full_control"}, {group="all", permission="read"}]

Defaults to the value specified in the application's this.s3.acl, which is "public" if unspecified.

Alias: acl

string, required

Type of file manipulation that the tag performs.

Note: action upload return the status of the upload operation as a struct after the file upload

string, optional

allow you to access filesystem, also when access is denied for your context

string, optional

Absolute pathname of file on web server. On Windows, use backward slashes; on UNIX, use forward slashes.

string, 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.

string, optional

Absolute pathname of directory or file on web server.

string, optional

Applies only to Solaris and HP-UX. Permissions. Octal values of UNIX chmod command. Assigned to owner, group, and other, respectively.

string, optional

Name of form field used to select the file.

string, optional

Character set name for the file contents.

string, optional

Action to take if filename is the same as that of a file in the directory.

  • skip
  • error
  • overwrite
  • makeunique
  • forceunique
string, optional

list of supported extensions or/and mimetypes.

boolean, optional

for action "upload" and "uploadAll":

if set to true (default), only mimetypes are supported.

boolean, optional

for action "append", "touch" and "write":

if set to false (default), expects all parent directories to exist, true will generate necessary directories

string, optional

Absolute pathname of file on web server.

string, optional

Name of variable to contain contents of text file.

any, optional

Content of the file to be created.

object, optional

possible values are:

  • String "request": If original content was created within the current request, cached content data is used.
  • a timespan (created with function CreateTimeSpan): If original content date falls within the time span, cached content data is used.

To use cached data, the tag must be called with the exact same arguments.

Only used by action "read" and "readbinary"


boolean, optional

Yes: appends newline character to text written to file

boolean, optional
  • true: changes embedded line-ending characters in string variables to operating-system specific line endings
  • false: (default) do not change embedded line-ending characters in string variables.
string, optional

Name of the result value (default:cffile)

any, optional

String list or string array of extensions allowed, this overwrites any other setting including the attribute [blockedExtensions] and settings done for example in the Application.cfc.

Alias: allowextension, allowedextension

any, optional

String list or string array of extensions blocked, this overwrites any setting done for example in the Application.cfc.

Alias: blockextension, blockedextension


Tag examples

File Upload

<cffile action="upload" destination="destination-directory" fileField="form.fileData" nameconflict="overwrite">

File Write

<cffile action="write" file="#expandPath("./myFile.txt")#" output="Content that you need to write.">

File Read

<cffile action="read" file="#expandpath("./myfile.pdf")#" variable="myfile">

File Rename

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

File Move

<cffile action="move" source="#expandpath("./myfile.pdf")#" destination="#expandpath("./some/moveditems/")#">

File Copy

<cffile action="copy" source="#expandpath("./myfile.pdf")#" destination="#expandpath("./some/copypath/")#">

File Delete

<cffile action="delete" file="#expandpath("./some/moveditems/")#">

Script Examples

File Upload

result = fileupload(getTempDirectory(),"form.fileData"," ","makeunique");

File Write

filewrite(file="#expandPath("./myFile.txt")#" data="Content that you need to write.");

File Read

result = fileread(file="#expandPath("./myFile.txt")#");

File Rename


File Move


File Copy


File Delete


See also