h

플래쉬에서 PHP와 연동하면서 파일 업로드

· 2007-07-28 (토) 23:56:29 · 4611

안녕하세요.
홈피에 등록하면서 인사로 플래쉬에서 파일의 업로드에 대하여 써봅니다.
플래쉬와 PHP를 연동하려면 플래쉬쪽에서 파일을 업로드 하고 PHP쪽에서 업로드된파일을 받아 처리합니다.
플래쉬쪽에서의 액션코드를 보면 다음과 같습니다.
System.security.allowDomain("http://localhost/");
import flash.net.FileReference;

var allTypes:Array = new Array();
var imageTypes:Object = new Object();
imageTypes.description = "Images (*.jpg, *.jpeg, *.gif, *.png)";
imageTypes.extension = "*.jpg; *.jpeg; *.gif; *.png";
allTypes.push(imageTypes);

var listener:Object = new Object();

listener.onSelect = function(file:FileReference):Void {
    trace("onSelect: " + file.name);
 trace(this);
    if(!file.upload("http://localhost/fileupload.php")) {
        trace("Upload dialog failed to open.");
    }
}

listener.onCancel = function(file:FileReference):Void {
    trace("onCancel");
}

listener.onOpen = function(file:FileReference):Void {
    trace("onOpen: " + file.name);
}

listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
    trace("onProgress with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal);
}

listener.onComplete = function(file:FileReference):Void {
    trace("onComplete: " + file.name);
}

listener.onHTTPError = function(file:FileReference):Void {
    trace("onHTTPError: " + file.name);
}

listener.onIOError = function(file:FileReference):Void {
    trace("onIOError: " + file.name);
}

listener.onSecurityError = function(file:FileReference, errorString:String):Void {
    trace("onSecurityError: " + file.name + " errorString: " + errorString);
}

var fileRef:FileReference = new FileReference();
fileRef.addListener(listener);
fileRef.browse(allTypes);//파일다이얼로그열기 여기서 파일을 선택하지요.


PHP에서는 다음의 코드를 씁니다.(fileupload.php)
<?php
$f = $HTTP_POST_FILES['Filedata'];

 $filename = "1.aa";
if (!copy($a['tmp_name'],$filename)) {
    print ("failed to copy $file...<br>\n");
}
 ?>
위에서 보시는 바와 같이 플래쉬와 PHP는 대단히 쉬워요.

구체적인 설명이 요구되시면 문의 부탁...
안녕

[이 게시물은 관리자님에 의해 2011-10-31 16:50:06 Flash에서 이동 됨]
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

8,188건
+
제목 글쓴이 날짜 조회
12-01-11 조회 2,746
12-01-11 조회 1.2만
12-01-10 조회 2,845
12-01-08 조회 3,439
12-01-05 조회 5,331
11-12-29 조회 3,048
11-12-27 조회 2,833
11-12-25 조회 3,016
11-12-22 조회 3,453
11-12-14 조회 2,916
11-12-12 조회 3,533
11-11-28 조회 3,375
10-10-19 조회 2,834
08-09-05 조회 3,754
08-09-05 조회 3,569
08-06-14 조회 3,314
08-04-22 조회 3,589
08-04-17 조회 3,594
07-10-03 조회 4,210
07-10-03 조회 3,605
07-10-03 조회 7,286
07-10-03 조회 4,564
07-10-03 조회 3,262
07-10-03 조회 2,853
07-10-02 조회 3,569
07-10-02 조회 3,099
07-09-27 조회 5,016
07-09-27 조회 3,842
06-09-26 조회 3,514
06-09-26 조회 4,730
06-09-22 조회 3,905
06-09-22 조회 3,521
06-09-22 조회 4,268
06-09-21 조회 4,201
06-08-18 조회 3,691
05-11-30 조회 4,740
05-07-15 조회 4,587
05-03-23 조회 4,651
05-03-14 조회 3,319
05-03-13 조회 2,695
04-08-05 조회 5,767