User Guide

220 Developing Web Applications with ColdFusion
Using CFFILE
The CFFILE tag gives you the ability to work with files on your server in a number of
ways:
Uploading files from a client to the Web server using an HTML form.
Moving, renaming, copying, or deleting files on the server.
Reading, writing, or appending to text files on the server.
The required attributes depend on the ACTION specified. For example, if
ACTION="WRITE", ColdFusion expects the attributes associated with writing a text
file.
Note Consider the security and logical structure of directories on the server
before allowing users access to them.
Uploading Files
File uploading requires that you create two files:
An HTML form to enter file upload information
An action page containing the file upload code
To create an HTML file to specify file upload information:
1. Create a new file in Studio.
2. Modify the file so that it appears as follows:
<HTML>
<HEAD>
<TITLE>Specify File to Upload</TITLE>
</HEAD>
<BODY>
<H2>Specify File to Upload</H2>
<FORM ACTION="uploadfileaction.cfm"
4 ENCTYPE="multipart/form-data"
METHOD="post">
<P>Enter the complete path and filename of the file to upload:
<INPUT TYPE="file"
NAME="FiletoUpload"
SIZE="45">
</P>
<INPUT TYPE="submit"
VALUE"Upload">
</FORM>
</BODY>
</HTML>
3. Save the file as uploadfileform.cfm in myapps under the Web root directory.