Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 399

Programming actionscript 3.0
Table of Contents

Advertisement

The
parameter contains an invalid protocol. The
url
method must use either HTTP or HTTPS.
Flash Player does not offer complete support for servers that require authentication.
Only SWF files that are running in a browser using the browser plug-in or ActiveX control
can provide a dialog box to prompt the user to enter a user name and password for
authentication, and then only for downloads. For uploads using the plug-in or ActiveX
control or upload/download using either the stand-alone or external player, the file
transfer fails.
If you create a server script in ColdFusion to accept a file upload from Flash Player, you can
use code similar to the following:
<cffile action="upload" filefield="Filedata" destination="#ExpandPath('./
')#" nameconflict="OVERWRITE" />
This ColdFusion code uploads the file sent by Flash Player and saves it to the same directory
as the ColdFusion template, overwriting any file with the same name. The previous code
shows the bare minimum amount of code necessary to accept a file upload; this script should
not be used in a production environment. Ideally, you should add data validation to ensure
that users upload only accepted file types, such as an image instead of a potentially dangerous
server-side script.
The following code demonstrates file uploads using PHP, and it includes data validation. The
script limits the number of uploaded files in the upload directory to 10, ensures that the file is
less than 200 KB, and permits only JPEG, GIF, or PNG files to be uploaded and saved to the
file system.
<?php
$MAXIMUM_FILESIZE = 1024 * 200; // 200KB
$MAXIMUM_FILE_COUNT = 10; // keep maximum 10 files on server
echo exif_imagetype($_FILES['Filedata']);
if ($_FILES['Filedata']['size'] <= $MAXIMUM_FILESIZE)
{
move_uploaded_file($_FILES['Filedata']['tmp_name'], "./temporary/
".$_FILES['Filedata']['name']);
$type = exif_imagetype("./temporary/".$_FILES['Filedata']['name']);
if ($type == 1 || $type == 2 || $type == 3)
{
rename("./temporary/".$_FILES['Filedata']['name'], "./images/
".$_FILES['Filedata']['name']);
}
else
{
unlink("./temporary/".$_FILES['Filedata']['name']);
}
}
$directory = opendir('./images/');
FileReference.upload()
Working with file upload and download
399

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents