<!--- This file demonstrates the ability to write, read,
update, and delete a file using the CFFILE command --->
<HTML>
<HEAD>
<TITLE>CFFILE Example</TITLE>
</HEAD>

<BASEFONT FACE="Arial, Helvetica" SIZE=2>
<BODY  bgcolor="#FFFFD5">

<H3>CFFILE Example</H3>

The is a read-only example. Because file access
is a sensitive area, consider the security of your directory hierarchy
before allowing access to it. 

<!--- <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="cffile.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 we are reading from a form, allow that information
to be displayed in the textarea --->
<TEXTAREA NAME="the_text" COLS="40" ROWS="5">
<CFIF readText is not "">
	<CFOUTPUT>#readText#</CFOUTPUT>
</CFIF></TEXTAREA>

<!--- select from the available actions depending on
whether the file exists or not --->
<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>
 --->
</BODY>
</HTML>       
