home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 February / CHIPCD_02_2002.iso / Internet / Macromedia ColdFusion Server 5 / coldfusion-50-win-us.exe / data1.cab / Examples / CFDOCS / snippets / cffile.cfm < prev    next >
Encoding:
Text File  |  2001-06-13  |  2.5 KB  |  92 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. <BASEFONT FACE="Arial, Helvetica" SIZE=2>
  9. <BODY  bgcolor="#FFFFD5">
  10.  
  11. <H3>CFFILE Example</H3>
  12.  
  13. The is a read-only example. Because file access
  14. is a sensitive area, consider the security of your directory hierarchy
  15. before allowing access to it. 
  16.  
  17. <!--- <CFIF IsDefined("form.formsubmit") is "Yes">
  18. <!--- form has been submitted, now do the action --->
  19.     <CFIF form.action is "new">
  20.     <!--- make a new file --->
  21.         <CFFILE ACTION = "Write"
  22.             FILE = "#GetTempDirectory()#foobar.txt"
  23.             OUTPUT="#form.the_text#">
  24.     </CFIF>
  25.     
  26.     <CFIF form.action is "read">
  27.     <!--- read existing file --->
  28.         <CFFILE ACTION = "Read"
  29.             FILE = "#GetTempDirectory()#foobar.txt"
  30.             VARIABLE = "readText">
  31.     </CFIF>
  32.     <CFIF form.action is "add">
  33.     <!--- update existing file --->
  34.         <CFFILE ACTION = "Append"
  35.             FILE = "#GetTempDirectory()#foobar.txt"
  36.             OUTPUT="#form.the_text#">
  37.     </CFIF>
  38.     <CFIF form.action is "delete">
  39.     <!--- delete existing file --->
  40.         <CFFILE ACTION = "Delete"
  41.             FILE = "#GetTempDirectory()#foobar.txt">
  42.  
  43.     </CFIF>    
  44. </CFIF>
  45.  
  46. <!--- set some variables --->
  47. <CFPARAM name="fileExists" default="no">
  48. <CFPARAM name="readText" default ="">
  49.  
  50. <!--- first, check if canned file exists --->
  51. <CFIF FileExists("#GetTempDirectory()#foobar.txt") is "Yes">
  52.   <CFSET fileExists="yes">
  53. </CFIF>
  54.  
  55. <!--- now, make the form that runs the example --->
  56. <FORM ACTION="cffile.cfm" METHOD="POST">
  57.  
  58. <H4>Type in some text to include in your file:</H4>
  59.  
  60. <P>
  61. <CFIF fileExists is "yes">
  62.   A file exists (foobar.txt, in <CFOUTPUT>#GetTempDirectory()#</CFOUTPUT>). 
  63.   You may add to it, read from it, or delete it.
  64. </CFIF>
  65.  
  66. <!--- if we are reading from a form, allow that information
  67. to be displayed in the textarea --->
  68. <TEXTAREA NAME="the_text" COLS="40" ROWS="5">
  69. <CFIF readText is not "">
  70.     <CFOUTPUT>#readText#</CFOUTPUT>
  71. </CFIF></TEXTAREA>
  72.  
  73. <!--- select from the available actions depending on
  74. whether the file exists or not --->
  75. <SELECT NAME="action">
  76. <CFIF fileExists is "no">
  77.     <OPTION value="new">Make new file
  78. </CFIF>
  79. <CFIF fileExists is "yes">
  80.     <OPTION value="add">Add to existing file
  81.     <OPTION value="delete">Delete file
  82.     <OPTION value="read">Read existing file
  83. </CFIF>
  84. </SELECT>
  85.  
  86. <INPUT TYPE="Hidden" NAME="formsubmit" VALUE="yes">
  87. <INPUT TYPE="Submit" NAME="" VALUE="make my changes">
  88. </FORM>
  89.  --->
  90. </BODY>
  91. </HTML>       
  92.