13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Working with the file system<br />

Flash Player does not offer complete support for servers that require auth<strong>en</strong>tication. Only SWF files that are running<br />

in a browser using the browser plug-in or Microsoft ActiveX® control can provide a dialog box to prompt the user to<br />

<strong>en</strong>ter a user name and password for auth<strong>en</strong>tication, and th<strong>en</strong> only for downloads. For uploads using the plug-in or<br />

ActiveX control or upload/download using either the stand-alone or external player, the file transfer fails.<br />

To create a server script in ColdFusion to accept a file upload from Flash Player, you can use code similar to the<br />

following:<br />

<br />

This ColdFusion code uploads the file s<strong>en</strong>t by Flash Player and saves it to the same directory as the ColdFusion<br />

template, overwriting any file with the same name. The previous code shows the bare minimum amount of code<br />

necessary to accept a file upload; this script should not be used in a production <strong>en</strong>vironm<strong>en</strong>t. Ideally, add data<br />

validation to <strong>en</strong>sure that users upload only accepted file types, such as an image instead of a pot<strong>en</strong>tially dangerous<br />

server-side script.<br />

The following code demonstrates file uploads using PHP, and it includes data validation. The script limits the number<br />

of uploaded files in the upload directory to 10, <strong>en</strong>sures that the file is less than 200 KB, and permits only JPEG, GIF, or<br />

PNG files to be uploaded and saved to the file system.<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!