User Guide

Uploading Files 321
Reviewing the code
The following table describes the code and its function:
Note
This example performs no error checking and does not incorporate any security
measures. Before deploying an application that performs file uploads, be sure to
incorporate both error handling and security.
Resolving conflicting filenames
When you save a file to the server, there is a risk that another file might already exist
with the same name. In this case, there are a number of actions that you can take
using the
nameConflict attribute. For example, you can specify the parameter
nameConflict="makeunique" in the cffile tag to create a unique filename while
keeping the file extension the same. The unique name might not resemble the
attempted name.
Controlling the type of file uploaded
For some applications, you might want to restrict the type of file that is uploaded. For
example, you might not want to accept graphic files in a document library.
You use the accept attribute to restrict the type of file that you allow in an upload.
When an
accept qualifier is present, the uploaded files MIME content type must
match the criteria specified or an error occurs. The
accept attribute takes a
comma-separated list of MIME data names, optionally with wildcards.
A files MIME type is determined by the browser. Common types, like image/gif and
text/plain, are registered in your browser.
Code Description
<cffile action="upload"
Prepare to upload a file to the server.
destination="c:\temp"
Specify the destination of the file.
nameConflict="overwrite"
If the file already exists, overwrite it.
fileField="Form.FiletoUpload">
Specify the name of the file to upload.
Note that you do not enclose the variable
in pound signs.
You uploaded the file
#cffile.ClientFileName#.#cffile.
ClientFileExt# successfully to
#cffile.ServerDirectory#\#cffile.
ServerFileName#.#cffile.ServerFileExt#.
Inform the user of the file that was
uploaded and its destination. For
information on cffile scope variables, see
Evaluating the Results of a File Upload
on page 324.