View comments | RSS feed
Contents > CFML Reference > ColdFusion Tags > cffile PreviousNext

cffile

Manages interactions with server files.

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

File management tags

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

cfdirectory

ColdFusion MX 6.1:

ColdFusion MX:

<!--- 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> --->

Contents > CFML Reference > ColdFusion Tags > cffile PreviousNext

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


lbryngel said on Feb 23, 2004 at 1:58 PM :
REMOVE NOTE:
"Note: This tag executes only if it is enabled in the ColdFusion Administrator. For more information, see Configuring and Administering ColdFusion MX."

The "Tag Restriction" page is not in CFMX 6.x Adminstrator - it was only in CF 5. To restrict this tag in CFMX use Sandbox Security.
csteinola said on Mar 29, 2004 at 10:18 AM :
"To restrict this tag in CFMX use Sandbox Security"

... which you set up via CF Administrator, according to the [i]Configuring and Administering ColdFusion MX[/i] documentation.

I don't see the distinction you're trying to make, lbryngel. The note seems quite accurate to me.
lbryngel said on Mar 29, 2004 at 3:05 PM :
csteinola - In CF 5 there was a page called "Tag Restriction" in the CF Admin where you needed to make sure that this tag was enabled for it to be used. In CFMX 6.1 there is no tag restriction page and only if you use Sandbox Security will this tag be restricted. This note is an abreviated version from the CF 5 docs.

I found this line confusing because - I read this line - This tag executes only if it is enabled in the ColdFusion Administrator -
AND interpreted it as
"I need to check some setting in the CFMX 6.1 admin before using cffile to make sure that it's enabled like I did in CF 5 . So when I went into the CF Admin to look for the setting I'm like what the hay where is that setting?"
MaestroFJP said on Aug 23, 2004 at 8:22 AM :
Is the cffile "global" scope thread-safe in a persistant cfc enviroment or do you need to instantiate a new Input/Output object to maintain thread-safety?

You cannot "var" cffile to create a private variable at the begining of your method. After calling <cffile ...> is it sufficient to dupCffile = duplicate(cffile) to return at the end of the method?

Would it be thread-safe, if you temporarily instiantiate a new Input/Output cfc into the private scope (by var) in an persistant scope CFC in which your I/O would be gone when the method that called it was finished?
MaestroFJP said on Aug 24, 2004 at 1:19 PM :
This currently read: "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."

I believer it should read: "Changed behavior for action="upload" nameConflict="MakeUnique" ColdFusion MX 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 older version of ColdFusion, filenames were made unique by appending an additional "1" for each file, as in 1, 11, 111, and so on."
mindtrap said on Jan 14, 2005 at 6:43 AM :
It seems to me that cffile is a very slow asynchronous function. I cannot perform two cffile actions one right after the other except in the case of read, write and append.

For example, I cannot use action="upload" on a file then action="copy " right afterwards.

Why? This is very dumb behaviour. We were having the same problem with cf4.5 and cf5.0. Is it because the file is left open?
mydognacho said on Feb 9, 2005 at 7:33 AM :
I have GOT to be expressing the feelings of many users in saying that liveDocs is completely worthless. I have the ColdFusion 5 language reference book put out by Macromedia. I'm looking in the book under CFFILE and it says that a valid object variable for CFFILE is FILE.CONTENTTYPE. I attempt to use this in CFMX 6.1 and get the error "Element CONTENTTYPE is undefined in FILE. ".

Fine...so I come to LiveDocs to search for the correct answer and DO NOT even find a list of FILE object variables.

This should be the FIRST thing you focus on Macromedia. Either that or put out a language reference book for version 6 or version 7 so that I don't have to waste my time coming to LiveDocs only to find nothing on my search.
AccentGeoff said on Mar 3, 2005 at 4:59 AM :
I disagree with your sentiments mydognacho. Try clicking links - click on 'cffile action = "upload"' link above to see file parameters. You need to use the 'cffile' prefix rather than just 'file' now.
Tacs said on Jul 19, 2005 at 12:51 PM :
The true problem with the documentation is that people never use the arrows. PHP (http://www.php.net) does their documentation perfectly fine without requiring users to click on arrows to move to a new page. I propose that the documentation be placed on one page for each function. If Macromedia likes, they can use html links within a page, like http://www.mypage.com#myLink
No screen name said on Oct 13, 2005 at 3:06 PM :
cffile is a dog for doing appends and writing large files. Using native Java is much faster. I use the <a href="http://cfthishelps.blogspot.com/2005/09/writing-large-output-files-with.html">ColdFusion Java FileWriter.cfc</a>.

Here are some other <a href="http://www.informationsavvy.com/coldfusion/">other useful ColdFusion Java CFCs for file and string operations</a>.

 

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-p27.htm