User Guide

Table Of Contents
Using cffile 1011
Writing a text file on the server
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 to capture data for a text file:
1.
Create a ColdFusion page with the following content:
<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 your name: <input type="text" name="Name" size="25"></p>
<p>Enter the name of the file: <input type="text" name="FileName"
size="25">.txt</p>
<p>Enter your message:
<textarea name="message"cols=45 rows=6></textarea>
</p>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
2.
Save the file as writetextfileform.cfm in the myapps directory under your web_root.
Note: The form will not work until you write an action page for it (see the next procedure).
To write a text file:
1.
Create a ColdFusion page with the following content:
<html>
<head>
<title>Write a Text File</title>
</head>
<body>
<cffile action="write"
file="C:\inetpub\wwwroot\mine\#Form.FileName#.txt"
output="Created By: #Form.Name#
#Form.Message# ">
</body>
</html>
2.
Modify the path C:\inetpub\wwwroot\mine\ to point to a path on your server.
3.
Save the file as writetextfileaction.cfm in the myapps directory under your web_root.
4.
View the file writetextfileform.cfm in the browser, enter values, and submit the form.
The text file is written to the location you specified. If the file already exists, it is replaced.