iHelpers 의 손상모님의 글을 허락없이 퍼왔습니다. ^^;

FileUpDown.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
 <mx:Script>
  <![CDATA[
   import mx.controls.Alert;
   
   private var fr:FileReference;;

   public function Download():void {
 
    fr = new FileReference();  
    fr.addEventListener(Event.OPEN,onOpenFile);
    fr.addEventListener(ProgressEvent.PROGRESS,onFileProgress);
    fr.addEventListener(Event.COMPLETE,onCompleteDownload);
   
    var request:URLRequest = new URLRequest();
    request.url = "rank.tar.gz";
   
    try {
     fr.download(request);
    } catch (e:SecurityError){
     Alert.show(e.toString());
    }
   }

   public function onOpenFile(event:Event):void {
    dpg.label = '다운로드 %3%%';
   }
   
   public function onCompleteDownload(event:Event):void {
    Alert.show('다운로드 완료');
   }
   
   public function onFileProgress(event:ProgressEvent):void {
    dpg.setProgress(event.bytesLoaded,event.bytesTotal);
   }
   
   public function Upload():void {
   
    fr = new FileReference();
    fr.addEventListener(Event.SELECT,onUploadSelectFile);
    fr.addEventListener(Event.OPEN,onUploadOpenFile);
    fr.addEventListener(ProgressEvent.PROGRESS,onUploadFileProgress);
    fr.addEventListener(Event.COMPLETE,onUploadCompleteDownload);

    var imgFilter:FileFilter = new FileFilter("Images(*.png;*.gif;*.jpg)","*.png;*.gif;*.jpg");
    var arcFilter:FileFilter = new FileFilter("Archives(*.zip;*.gz;*.tar)","*.zip;*.gz;*.tar");
    var allFilter:FileFilter = new FileFilter("All(*.*)","*.*");
    fr.browse([imgFilter,arcFilter,allFilter]);  

   }

   public function onUploadSelectFile(event:Event):void {
    var request:URLRequest = new URLRequest();
    request.url = "upload.php";
       
    try {
     fr.upload(request,"file");
    } catch (e:SecurityError){
     Alert.show(e.toString());
    }   
   }
   
   public function onUploadOpenFile(event:Event):void {
    upg.label = '업로드 %3%%';
   }
   
   public function onUploadCompleteDownload(event:Event):void {
    Alert.show('업로드 완료');
   }
   
   public function onUploadFileProgress(event:ProgressEvent):void {
    upg.setProgress(event.bytesLoaded,event.bytesTotal);
   }
  ]]>
 </mx:Script>
 <mx:Button x="10" y="10" label="Dowload" click="Download()"/>
 <mx:Label id="filepg" x="93" y="12"/>
 <mx:ProgressBar x="10" y="38" width="351" label="" id="dpg" mode="manual"/>
 <mx:ProgressBar x="10" y="110" width="351" label="" id="upg" mode="manual"/>
 <mx:Button x="10" y="80" label="Upload" click="Upload()" width="75"/>
</mx:Application>

========================================================================================
upload.php
<?
$file_temp = $_FILES['file']['tmp_name'];
$file_name = $_FILES['file']['name'];
$file_size = $_FILES['file']['size'];

$updir = "D:/wwwroot/test/html/upload";

if(!empty($file_name)){
 $filename = sprintf("%s/%s",$updir,$file_name);
 $filename = iconv("UTF-8", "EUC-KR",$filename);  // 한글처리

 if(!file_exists($filename)) {
  if(move_uploaded_file($file_temp,$filename)){
  } else {
  }
 }
}

fclose($fp);
?>

'Dev' 카테고리의 다른 글

Tomcat에서 JSP파일의 한글깨짐 방지  (1) 2007.11.23
[펌] Java를 이용한 Flex 파일 업로드  (0) 2007.11.22
Flex Ant Task를 이용한 자동화 빌드 구축하기  (0) 2007.11.15
flex 라이센스키  (0) 2007.11.14
AS3 한글  (63) 2007.08.06

+ Recent posts