CFFILE |
Description Manages interactions with server files. The following sections describe the actions of the cffile tag: cffile action = "append" on page 383 cffile action = "copy" on page 385 cffile action = "delete" on page 387 cffile action = "move" on page 388 cffile action = "read" on page 390 cffile action = "readBinary" on page 392 cffile action = "rename" on page 393 cffile action = "upload" on page 395 cffile action = "write" on page 398
Note: | To execute, this tag must be enabled in the ColdFusion Administrator. For more information, see Configuring and Administering ColdFusion MX.
If your ColdFusion applications run on a server used by multiple customers, consider the security of the files that could be uploaded or manipulated by cffile. For more information, see Configuring and Administering ColdFusion MX.
Category File management tags
Syntax The tag syntax depends on the action attribute value. See the following sections. cffile action = "append" cffile action = "copy" cffile action = "delete" cffile action = "move" cffile action = "read" cffile action = "readBinary" cffile action = "rename" cffile action = "upload" cffile action = "write"
See also cfdirectory
History ColdFusion MX 7: Added the result attribute, which allows you to specify an alternate variable in which to receive result parameters. Used for action = "upload" action. ColdFusion MX 6.1: Changed file path requirements: if you do not specify an absolute file path, the path is relative to the ColdFusion temporary directory, which is returned by the GetTempDirectory function. Changed behavior for action="read": if the file starts with a byte order mark (BOM) ColdFusion uses it to determine the character encoding. Changed behavior for action="upload" nameConflict="MakeUnique" ColdFusion now makes filenames unique by appending a incrementing number, 1 for the first file, 2 for the second and so on, to the name. In ColdFusion MX filenames were made unique by appending an additional "1" for each file, as in 1, 11, 111, and so on. ColdFusion MX: Changed use of slashes in paths: you can use forward (/) or backward (\) slashes in paths on both UNIX and Windows systems. Changed file hierarchy requirements: ColdFusion does not require that you put files and directories that you manipulate with this tag below the root of the web server document directory. Changed directory path requirements for the destination attribute: a directory path that you specify in the destination attribute does not require a trailing slash. Deprecated the system value of the attributes attribute. Deprecated the temporary value of the attributes attribute. In ColdFusion MX, it is a synonym for normal. It might not work in later releases. Changed the action attribute options read, write, append and move: they support a new attribute, charset. The archive value of the attributes attribute is obsolete and has no effect.
Example
    <!--- This shows how to write, read, update, and delete a file using CFFILE.
    This is a view-only example. --->
    <!---
    <cfif IsDefined("form.formsubmit") is "Yes">
       <!--- The form has been submitted, now do the action. --->
       <cfif form.action is "new">
          <!--- make a new file --->
          <cffile          action="Write"
             file="#GetTempDirectory()#foobar.txt"
             output="#form.the_text#">
       </cfif>
       <cfif form.action is "read">
          <!--- read existing file --->
          <cffile          action="Read"
                file="#GetTempDirectory()#foobar.txt"
                variable="readText">
       </cfif>

       <cfif form.action is "add">
          <!--- update existing file --->
          <cffile          action="Append"
             file="#GetTempDirectory()#foobar.txt"
             output="#form.the_text#">
       </cfif>

       <cfif form.action is "delete">
          <!--- delete existing file --->
          <cffile       action="Delete"
             file="#GetTempDirectory()#foobar.txt">
       </cfif>
    </cfif>
    <!--- Set some variables. --->
    <cfparam    name="fileExists"    default="no">
    <cfparam name="readText" default="">
    <!--- First, check whether canned file exists. --->
    <cfif FileExists("#GetTempDirectory()#foobar.txt") is "Yes">
       <cfset fileExists="yes">
    </cfif>
    <!--- Now, make the form that runs the example. --->
    <form action="index.cfm" method="POST">
    <h4>Type in some text to include in your file:</h4> <p>
    <cfif fileExists is "yes">
       <p>A file exists (foobar.txt, in <cfoutput>#GetTempDirectory()#</cfoutput>).
       You may add to it, read from it, or delete it. </p>
    </cfif>
    <!--- If reading from a form, let that information display in textarea. --->
    <textarea name="the_text" cols="40" rows="5">
       <cfif readText is not "">
          <cfoutput>#readText#</cfoutput>
       </cfif></textarea>
    <!--- Select from the actions depending on whether the file exists. --->
    <select name="action">
    <cfif fileExists is "no">
       <option value="new">Make new file
    </cfif>
    <cfif fileExists is "yes">
       <option value="add">Add to existing file
       <option value="delete">Delete file
       <option value="read">Read existing file
    </cfif>
    </select>
    <input type="Hidden" name="formsubmit" value="yes">
    <input type="Submit" name="" value="make my changes">
    </form> --->