User Guide

Working with file upload and download 403
The following code demonstrates the ColdFusion script, download.cfm, that downloads one
of two files from the server, depending on the value of a URL variable:
<cfparam name="URL.id" default="1" />
<cfswitch expression="#URL.id#">
<cfcase value="2">
<cfcontent type="text/plain" file="#ExpandPath('two.txt')#"
deletefile="No" />
</cfcase>
<cfdefaultcase>
<cfcontent type="text/plain" file="#ExpandPath('one.txt')#"
deletefile="No" />
</cfdefaultcase>
</cfswitch>
FileReferenceList class
The FileReferenceList class lets the user select one or more files to upload to a server-side
script. The file upload is handled by the
FileReference.upload() method, which must be
called on each file that the user selects.
The following code creates two FileFilter objects (
imageFilter and textFilter) and passes
them in an array to the
FileReferenceList.browse() method. This causes the operating
system file dialog box to display two possible filters for file types.
var imageFilter:FileFilter = new FileFilter("Image Files (*.jpg, *.jpeg,
*.gif, *.png)", "*.jpg; *.jpeg; *.gif; *.png");
var textFilter:FileFilter = new FileFilter("Text Files (*.txt, *.rtf)",
"*.txt; *.rtf");
var fileRefList:FileReferenceList = new FileReferenceList();
try
{
var success:Boolean = fileRefList.browse(new Array(imageFilter,
textFilter));
}
catch (error:Error)
{
trace("Unable to browse for files.");
}
Allowing the user to select and upload one or more files by using the FileReferenceList class is
the same as using
FileReference.browse() to select files, although the FileReferenceList
allows you to select more than one file. Uploading multiple files requires you to upload each
of the selected files by using
FileReference.upload(), as the following code shows:
var fileRefList:FileReferenceList = new FileReferenceList();
fileRefList.addEventListener(Event.SELECT, selectHandler);
fileRefList.browse();
function selectHandler(event:Event):void