In addition to managing files on the server, you can use CFFILE to read, create, and modify text files.
This gives you the ability to
You can use CFFILE to read an existing text file. The file is read into a dynamic parameter which you can use anywhere in the application page. For example, you could read a text file and then insert its contents into a database. Or you could read a text file and then use one of the find and replace functions to modify the contents.
![]() |
To read a text file: |
<HTML> <HEAD> <TITLE>Read a Text File</TITLE> </HEAD> <BODY> Ready to read the file:<BR> <CFFILE ACTION="Read" FILE="C:\inetpub\wwwroot\mine\message.txt" VARIABLE="Message"> <CFOUTPUT> #Message# </CFOUTPUT> </BODY> </HTML>
c:\inetpub\wwwroot\mine\message.txt
with the location and name of a text file on your server.
readtext.cfm
and view it in your browser.
You can use CFFILE to write a text file based on dynamic content. For example, you could create static HTML files or log actions in a text file.
![]() |
To create a form in which to enter data for a text file: |
<HTML> <HEAD> <TITLE>Put Information into a Text File</TITLE> </HEAD> <BODY> <H2>Put Information into a Text File</H2> <FORM ACTION="writetextfileaction.cfm" METHOD="POST"> <p>Enter you name: <INPUT TYPE="text" NAME="Name" SIZE="25"> <p>Enter you the name of the file: <INPUT TYPE="text" NAME="FileName" SIZE="25"> <p>Enter your message:</p> <INPUT TYPE="textarea" NAME="message"cols=45 rows=6> </p> <INPUT TYPE="submit" NAME="submit" VALUE="Submit"> </FORM> </BODY> </HTML>
writetextfileform.cfm
in myapps
under the Web root directory.
![]() |
To write a text file: |
<HTML> <HEAD> <TITLE>Untitled</TITLE> </HEAD> <BODY> <CFFILE ACTION="Write" FILE="C:\inetpub\wwwroot\mine\#form.filename#" OUTPUT="Created By: #Form.Name# #Form.Message# "> </BODY> </HTML>
writetextfileaction.cfm
.
writetextfileform.cfm
in your browser, enter values, and submit the form.
The text file is written to the location you specified.
You can use CFFILE ACTION="Append"
to append additional text to the end of an existing text file, for example, when creating log files.