upload.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
private var fileR:FileReference=new FileReference()
/* 限制只能上传图片 */
private var filet:FileFilter=new FileFilter("Images","*.jpg;*.png;*.gif")
private function browse():void{
fileR.addEventListener(Event.Select,handSel)
fileR.browse([filet])
}
private function handSel(e:Event):void{
filename.text=fileR.name
}
private function upload_():void{
fileR.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,handUpCom)
var urlR:URLRequest=new URLRequest("
http://localhost/upload1.php")
fileR.upload(urlR)
}
private function handUpCom(e:DataEvent):void{
tea.text=e.data as String
}
]]>
</mx:Script>
<mx:TextInput id="filename" x="10" y="10" fontSize="12"/>
<mx:Button x="178" y="10" label="浏览" fontSize="12" click="browse()"/>
<mx:Button x="251" y="10" label="上传" fontSize="12" click="upload_()"/>
<mx:TextArea id="tea" x="10" y="93" width="478" height="238"/>
</mx:Application>
upload1.php
<?php
echo "\nReceiving upload...\n";
echo "temporary file name = " . $_FILES['Filedata']['tmp_name']."\n";
echo "file name = " . $_FILES['Filedata']['name']."\n";
echo "file size = " . $_FILES['Filedata']['size']."\n";
echo "move file...\n";
move_uploaded_file($_FILES['Filedata']['tmp_name'], "upload/".$_FILES['Filedata']['name']);
echo "file moved\n";
?>