태터데스크 관리자

도움말
닫기
적용하기   첫페이지 만들기

태터데스크 메시지

저장하였습니다.

language/php2008/01/17 15:49

아래 코드는 Flex와 PHP를 이용해서 파일 업로드를 구현한 것이다.

FileUpDown.mxml (Language : xml)
<?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 (Language : 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);
?>
 


출처 : http://www.ihelpers.co.kr/programming/t ··· Bag%3Dpg 

'language > php' 카테고리의 다른 글

php 문자열 2차 배열 변환  (0) 2008/02/28
PHP 배열의 원리 - array()  (0) 2008/01/31
php-배열  (0) 2008/01/31
php- explode  (0) 2008/01/31
Flex & PHP 파일 업로드 소스  (0) 2008/01/17
php 메일 (첨부파일가능)  (1) 2008/01/16
Posted by THLIFE.net

TRACKBACK http://thlife.net/trackback/43 관련글 쓰기

댓글을 달아 주세요