UPLOAD + DOWNLOAD + POST + ENCODE + SAVE USING AS3 AND PHP

This series of classes easily manage the uploading, downloading, encoding and saving of files into and out of Flash to the server.


The Filez set is basically broken  into a series of 5 classes …

Filez_Uploader along with the accompanying PHP file  uploads files or images with some added features, among them the ability to  set a  maximum file size,  set a maximum number of files in the directory, and the option to overwrite another file or not.

Filez_Encoder encodes either a .JPG or .PNG image. It actually uses two separate types of custom encoders  based upon ADOBE’s JPGEncoder & PNGEncoder. The JPG encoder comes courtesy of  Eugene Zatepyakin. I made a few mods to the PNGEncoder to return a progress event.

Filez_Snapshot ( for Flash 10+ ) uses the FileReference method to save directly without needing any server side technology, so if you just need the ability to save directly from flash you could just use Filez_Encoder and Filez_Snapshot.

Filez_PostByteArray posts ByteArrays to a server. It uses Jonathan Marston’s UploadPostHelper. Unfortunately it doesn’t support a progress event on upload though it should work more than fine for small to medium files.

Filez_Downloader downloads a file from a passed URL.

A few things you might notice about the classes … I’ve opted to use callbacks as opposed to custom events since they seem more reliable and can easily pass arguments back with them.

Here’s a stripped down sample usage of the FilezEncoder class …

//   - import class ...
import com.patterntest.filez.*;

//    create instance ...
var filezEncoder:Filez_Encoder = new Filez_Encoder();

//    call Filez_Encoder ...
filezEncoder.go(clip,onProgress,onCompleteCallBack,alertCallBack,{});

//    callbacks ...
function onProgress(_percent:String):void {
txtArea.text = int(Number(_percent)*100) +" %";
}

function onCompleteCallBack(_byteArray:ByteArray):void {
txtArea.text = _byteArray.toString()
}

function alertCallBack(_alert:Array):void {
txtArea.appendText(_alert)
}

// begin encoding ...
imageEncoder.beginEncode();



ALL CONTENT PATTERNTEST ©