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 file’s 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 file’s 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.
Summary of Contents for COLDFUSION 5-DEVELOPING
Page 1: ...Macromedia Incorporated Developing ColdFusion Applications MacroMedia ColdFusion 5 ...
Page 58: ...38 Chapter 3 Querying a Database ...
Page 134: ...114 Chapter 7 Updating Your Database ...
Page 210: ...190 Chapter 10 Reusing Code ...
Page 232: ...212 Chapter 11 Preventing and Handling Errors ...
Page 238: ...218 Chapter 12 Using the Application Framework ...
Page 262: ...242 Chapter 12 Using the Application Framework ...
Page 278: ...258 Chapter 13 Extending ColdFusion Pages with CFML Scripting ...
Page 320: ...300 Chapter 15 Indexing and Searching Data ...
Page 336: ...316 Chapter 16 Sending and Receiving E mail ...
Page 374: ...354 Chapter 18 Interacting with Remote Servers ...