import flash.net.FileFilter;
import flash.net.FileReferenceList;
import fl.controls.Button;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.events.HTTPStatusEvent;
import flash.display.Loader;
import flash.net.URLRequest;
var choose_button:Button=new Button();
var upload_button:Button=new Button();
var loader:Loader=new Loader();
var reference_list:FileReferenceList=new FileReferenceList();
var url:URLRequest=new URLRequest("http://localhost/flashupload.php");
choose_button.label="选择文件";
upload_button.label="上传文件";
upload_button.move(100,50);
addChild(choose_button);
choose_button.move(300,100);
addChild(upload_button);
addChild(loader);
choose_button.addEventListener(MouseEvent.CLICK,choose_file);
upload_button.addEventListener(MouseEvent.CLICK,upload_start);
reference_list.addEventListener(Event.SELECT, selectHandle);
reference_list.addEventListener(Event.CANCEL, cancelHandle);
//reference_list.addEventListener(ProgressEvent.PROGRESS, progressHandler);
//reference_list.addEventListener(Event.COMPLETE, completeHandle);
//reference_list.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandle);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,load_complete);
function progressHandler(evt:ProgressEvent):void{
trace("ProgressEvent");
trace(evt.target.name+"="+evt.bytesLoaded)
}
function load_complete(evt:Event):void{
trace("load_complete");
}
function selectHandle(evt:Event):void{
trace("select file successfully");
trace("你选择了"+evt.target.fileList.length+"文件")
for(var i:int=0;i
trace(evt.target.fileList[i].name);
evt.target.fileList[i].addEventListener(ProgressEvent.PROGRESS, progressHandler);
evt.target.fileList[i].addEventListener(Event.COMPLETE, completeHandle);
evt.target.fileList[i].load();
}
//trace("type"+evt.target.fileList[0].type);
}
function cancelHandle(evt:Event):void{
trace("cnacel the file");
}
function httpStatusHandle(evt:HTTPStatusEvent):void{
trace("open file");
}
function completeHandle(evt:Event):void{
trace("completehandle");
var pic_loader:Loader=new Loader();
pic_loader.loadBytes(evt.target.data);
//loader.addChild(pic_loader);
this.addChild(pic_loader);
}
function choose_file(evt:MouseEvent):void{
reference_list.browse(get_file_type());
}
function get_file_type():Array{
var file_array=new Array();
file_array.push(new FileFilter("Images","*.jpg;*.jpeg;*.gif;*.png;*.rar;*.iso"));
return file_array;
}
function upload_start(evt:MouseEvent):void{
for(var i:int=0;i
reference_list.fileList[i].upload(url);
}
}
php ///
$uploaddir = 'aa/';
$filename = date("Ymdhis").rand(100,999);
$uploadfile = $uploaddir .$filename.substr($_FILES['Filedata']["name"],strrpos($_FILES['Filedata']["name"],"."));
$temploadfile = $_FILES['Filedata']['tmp_name'];
file_put_contents("catcah.txt",$_FILES['Filedata']['tmp_name']);
move_uploaded_file($temploadfile , $uploadfile);
?>