Chapter 14: Managing Files on the Server
227
Reading, Writing, and Appending to a Text File
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
•
Create log files.
•
Generate static HTML documents.
•
Use text files to store information that can be brought into Web pages.
Reading a text file
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:
1.
Create a new file in Studio.
2.
Modify the file so that it appears as follows:
<HTML>
<HEAD>
<TITLE>Read a Text File</TITLE>
</HEAD>
<BODY>
Ready to read the file:<BR>
4
<CFFILE ACTION="Read"
4
FILE="C:\inetpub\wwwroot\mine\message.txt"
4
VARIABLE="Message">
<CFOUTPUT>
#Message#
</CFOUTPUT>
</BODY>
</HTML>
3.
Replace
c:\inetpub\wwwroot\mine\message.txt
with the location and name of a
text file on your server.
4.
Save the file as
readtext.cfm
and view it in your browser.
Writing a text file
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.
Summary of Contents for COLDFUSION 4.5-DEVELOPING WEB
Page 1: ...Allaire Corporation Developing Web Applications with ColdFusion ColdFusion 4 5...
Page 14: ...xiv Developing Web Applications with ColdFusion...
Page 26: ...xxvi Developing Web Applications with ColdFusion...
Page 34: ...8 Developing Web Applications with ColdFusion...
Page 70: ...44 Developing Web Applications with ColdFusion...
Page 84: ...58 Developing Web Applications with ColdFusion...
Page 114: ...88 Developing Web Applications with ColdFusion...
Page 148: ...122 Developing Web Applications with ColdFusion...
Page 174: ...148 Developing Web Applications with ColdFusion...
Page 208: ...182 Developing Web Applications with ColdFusion...
Page 244: ...218 Developing Web Applications with ColdFusion...
Page 274: ...248 Developing Web Applications with ColdFusion...
Page 288: ...262 Developing Web Applications with ColdFusion...
Page 300: ...274 Developing Web Applications with ColdFusion...
Page 350: ...324 Developing Web Applications with ColdFusion...
Page 362: ...336 Developing Web Applications with ColdFusion...