home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 1999 April / APC443.iso / features / grpware / coldfus / coldfusi.exe / data1.cab / Documentation / snippets / cffile.cfm < prev    next >
Encoding:
Text File  |  1998-10-08  |  2.3 KB  |  86 lines

  1. <!--- This file demonstrates the ability to write, read,
  2. update, and delete a file using the CFFILE command --->
  3. <HTML>
  4. <HEAD>
  5. <TITLE>CFFILE Example</TITLE>
  6. </HEAD>
  7.  
  8. <BODY BGCOLOR="silver">
  9. <H3>CFFILE Example</H3>
  10.  
  11. <CFIF IsDefined("form.formsubmit") is "Yes">
  12. <!--- form has been submitted, now do the action --->
  13.     <CFIF form.action is "new">
  14.     <!--- make a new file --->
  15.         <CFFILE ACTION = "Write"
  16.             FILE = "#GetTempDirectory()#foobar.txt"
  17.             OUTPUT="#form.the_text#">
  18.     </CFIF>
  19.     
  20.     <CFIF form.action is "read">
  21.     <!--- read existing file --->
  22.         <CFFILE ACTION = "Read"
  23.             FILE = "#GetTempDirectory()#foobar.txt"
  24.             VARIABLE = "readText">
  25.     </CFIF>
  26.     <CFIF form.action is "add">
  27.     <!--- update existing file --->
  28.         <CFFILE ACTION = "Append"
  29.             FILE = "#GetTempDirectory()#foobar.txt"
  30.             OUTPUT="#form.the_text#">
  31.     </CFIF>
  32.     <CFIF form.action is "delete">
  33.     <!--- delete existing file --->
  34.         <CFFILE ACTION = "Delete"
  35.             FILE = "#GetTempDirectory()#foobar.txt">
  36.  
  37.     </CFIF>    
  38. </CFIF>
  39.  
  40. <!--- set some variables --->
  41. <CFPARAM name="fileExists" default="no">
  42. <CFPARAM name="readText" default ="">
  43.  
  44. <!--- first, check if canned file exists --->
  45. <CFIF FileExists("#GetTempDirectory()#foobar.txt") is "Yes">
  46.   <CFSET fileExists="yes">
  47. </CFIF>
  48.  
  49. <!--- now, make the form that runs the example --->
  50. <FORM ACTION="cffile.cfm" METHOD="POST">
  51.  
  52. <H4>Type in some text to include in your file:</H4>
  53.  
  54. <P>
  55. <CFIF fileExists is "yes">
  56.   A file exists (foobar.txt, in <CFOUTPUT>#GetTempDirectory()#</CFOUTPUT>). 
  57.   You may add to it, read from it, or delete it.
  58. </CFIF>
  59.  
  60. <!--- if we are reading from a form, allow that information
  61. to be displayed in the textarea --->
  62. <TEXTAREA NAME="the_text" COLS="40" ROWS="5">
  63. <CFIF readText is not "">
  64.     <CFOUTPUT>#readText#</CFOUTPUT>
  65. </CFIF></TEXTAREA>
  66.  
  67. <!--- select from the available actions depending on
  68. whether the file exists or not --->
  69. <SELECT NAME="action">
  70. <CFIF fileExists is "no">
  71.     <OPTION value="new">Make new file
  72. </CFIF>
  73. <CFIF fileExists is "yes">
  74.     <OPTION value="add">Add to existing file
  75.     <OPTION value="delete">Delete file
  76.     <OPTION value="read">Read existing file
  77. </CFIF>
  78. </SELECT>
  79.  
  80. <INPUT TYPE="Hidden" NAME="formsubmit" VALUE="yes">
  81. <INPUT TYPE="Submit" NAME="" VALUE="make my changes">
  82. </FORM>
  83.  
  84. </BODY>
  85. </HTML>       
  86.