improve algorithm (sssspeeeeddddd)

Technologies, Flash, Flex, Apollo, Adobe
package com.duemas.leonardo{
import flash.display.MovieClip;
import flash.events.*;
import com.duemas.leonardo.io.FileManager;
public class Example extends MovieClip{
public const IMPORT_IMAGE:String="importImage";
private var fileManager:FileManager;
public function Example(){
createInstance();
registerListeners();
startApp()
}
private function createInstance(){
fileManager =new FileManager();
}
private function registerListeners(){
this.addEventListener(IMPORT_IMAGE,fileManager.importImage);
fileManager.addEventListener(fileManager.ON_IMPORT_IMAGE,onImport);
}
private function onImport(ev:Event):void{
var f:FileManager=FileManager(ev.target);
var img_uploaded:String=f.lastFileSelect;
trace("image uploaded: "+img_uploaded);
}
private function startApp(){
var e =new Event(IMPORT_IMAGE);
dispatchEvent(e);
}
}
}
package com.duemas.leonardo.io
{
import flash.events.*;
import flash.net.*;
import com.duemas.leonardo.constant.Constant;
import flash.events.*
public class FileManager
{
public const ON_IMPORT_IMAGE:String="OnImportImage";
private var f:FileReference;
public var lastFileSelect:String;
private var imagesFilter:FileFilter;
public function FileManager()
{
super();
imagesFilter= new FileFilter("Images", "*.jpg;*.gif;*.png")
}
public function importImage(ev:Event){
f=new FileReference();
f.addEventListener(Event.SELECT,onFileSelect);
f.addEventListener(IOErrorEvent.IO_ERROR,errorFile);
f.addEventListener(Event.COMPLETE, uploadComplete);
f.browse([imagesFilter])
}
private function errorFile(e:IOErrorEvent){
trace("error "+e.toString())
}
private function uploadComplete(e:Event){
lastFileSelect=f.name;
var ev:Event=new Event(ON_IMPORT_IMAGE);
dispatchEvent(ev);
}
private function onFileSelect(e:Event):void{
var file:FileReference = FileReference(e.target);
trace("selectHandler: " + file.name );
var uploadUrl:URLRequest = new URLRequest();
uploadUrl.url = Constant.SERVER_URL+Constant.PHP_URL+Constant.UPLOAD_URL;
file.upload(uploadUrl)
}
}
}
package com.duemas.leonardo.constant
{
public class Constant
{
public static const SERVER_URL:String="http://localhost/leonardo/";
public static const PHP_URL:String="php/";
public static const UPLOAD_URL:String="upload.php";
public static const IMAGE_FOLDER:String="img/";
}
}
$destination_dir = '../img/';
if(
isset($_FILES['Filedata']) &&
is_array($_FILES['Filedata']) &&
isset(
$_FILES['Filedata']['tmp_name'],
$_FILES['Filedata']['name'],
$_FILES['Filedata']['size'],
$_FILES['Filedata']['error']
) &&
intVal($_FILES['Filedata']['error']) === 0
) {
if(move_uploaded_file($_FILES['Filedata']['tmp_name'], $destination_dir.$_FILES['Filedata']['name'])) {
$result = "
Date: ".date('Y-m-d H:i:s')."
File: {$_FILES['Filedata']['name']}
Size: {$_FILES['Filedata']['size']}
Successfull uploaded.
";
}
else {
$result = "
Date: ".date('Y-m-d H:i:s')."
File: {$_FILES['Filedata']['name']}
Size: {$_FILES['Filedata']['size']}
Error: {$_FILES['Filedata']['error']}
Unable to move file.
";
}
if(@$fp = fopen($destination_dir.'upload.txt', 'w')) {
fwrite($fp, $result);
fclose($fp);
}
}
package{
import flash.display.*;
import flash.events.*;
import flash.net.URLRequest;
public class Example extends Sprite {
function Example(){loadImage("bdog.jpg");}
public function loadImage(u:String){
var _loader:Loader = new Loader();
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);
var request:URLRequest = new URLRequest(u);
_loader.load(request);
addChild(_loader);
}
private function onComplete(ev:Event):void{
var loader:LoaderInfo = LoaderInfo(ev.target);
}
}
}