View comments | RSS feed

cffile

Description

Manages interactions with files on the ColdFusion server.

The following sections describe the actions of the cffile tag:

Note:   To execute, this tag must be enabled in the ColdFusion Administrator. For more information, see 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 Administering ColdFusion MX.

Category

File management tags

Syntax

The tag syntax depends on the action attribute value. See the following sections.

See also

cfdirectory

History

New in ColdFusion MX: 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.

New in ColdFusion MX: A directory path that you specify in the destination attribute does not require a trailing slash.

New in ColdFusion MX: on Windows platforms, the temporary, archive, and system values of the attributes attribute 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: The action attribute options read, write, append and move support a new attribute, charset.

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"> 
  <!--- 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 if 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"> 
  A file exists (foobar.txt, in <cfoutput>#GetTempDirectory()#</cfoutput>). 
  You may add to it, read from it, or delete it. 
</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> --->

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

Version 6

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

Comments


hlichtin said on Jun 3, 2003 at 11:13 AM :
Only the System, Temporary, and Archive values of the attributes attribute are deprecated. The tag is not deprecated.
psychogears said on Jun 2, 2003 at 11:24 PM :
If this tag is listed in the Deprecated tags listing, what should we use instead of cffile to upload via HTTP?
&&&&&& said on Jun 17, 2004 at 2:10 PM :
Is there anyway to upload more than one file at a time?
No screen name said on May 18, 2005 at 1:39 PM :
" Is there anyway to upload more than one file at a time?"

yep. took me a while to figure it out, but it's simple.

i had to upload to images, one named small_image, and the other named large_image. here is m code:

<cffile destination="#dest#" action="upload" nameconflict="overwrite" filefield="image_small">
<cfset name_small = #FILE.ServerFile#>
<cffile destination="#dest#" action="upload" nameconflict="overwrite" filefield="image_large">
<cfset name_large = #FILE.ServerFile#>

i needed the file names (hence the #FILE.ServerFile#) to insert them into a MySQL database.

 

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

Current page: http://livedocs.adobe.com/coldfusion/6/CFML_Reference/Tags-pt128.htm