posts - 17, comments - 4, trackbacks - 0, articles - 0
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          [原]Flex上傳組件

          Posted on 2007-08-28 18:37 愚人 閱讀(1258) 評論(0)  編輯  收藏 所屬分類: Flex2
          自己做了個小小的上傳組件雛形,大概的功能有了,還請高手多多指點,嘿嘿

           1<?xml version="1.0" encoding="utf-8"?>
           2<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init()" width="400" height="300">
           3    <mx:Script>
           4        <![CDATA[
           5            import mx.controls.Alert;
           6            public var UrlUpload:String ;
           7            public var editable:Boolean = false ;
           8            
           9            private var urlRequest:URLRequest ;
          10            private var fileList:Array ;
          11            private var fileReferenceList:FileReferenceList ;
          12            private var filterArray:Array = [new FileFilter("圖片(*.gif;*.png)","*.gif;*.png"),new FileFilter("視頻(*.avi;*.rmvb)","*.avi;*.rmvb")] ;
          13            private var count:int = 1 ;
          14            
          15            private function init():void
          16            {
          17                if( UrlUpload != null )
          18                {
          19                    urlRequest = new URLRequest(UrlUpload) ;
          20                    fileReferenceList = new FileReferenceList() ;
          21                    fileReferenceList.addEventListener(Event.SELECT,selectHandler) ;
          22                    broswer.addEventListener(MouseEvent.CLICK,broswe);
          23                }
          24            }
          25            
          26            private function selectHandler(event:Event):void
          27            {
          28                fileReferenceList = FileReferenceList(event.target) ;
          29                fileList = fileReferenceList.fileList ;
          30                filename.text = FileReference(fileList[0]).name ;
          31                upup.visible = true ;
          32                upup.addEventListener(MouseEvent.CLICK,upload) ;
          33            }
          34            
          35            private function upload(event:Event):void
          36            {
          37                
          38                var fileReference:FileReference = new FileReference() ;
          39                for( var i:int = 0; i<fileList.length; i++ )
          40                {
          41                    fileReference = FileReference(fileList[i]) ;
          42                    fileReference.addEventListener(Event.COMPLETE,dotrace);
          43                    //可以在這里命名文件field,后臺接受時對應html的name,默認為Filedata。方法:fileReference.upload(urlRequest,"filename") ;
          44                    fileReference.upload(urlRequest) ;
          45                }
          46            }
          47            
          48            private function dotrace(event:Event):void
          49            {
          50                if( count < fileList.length )
          51                {
          52                    count++ ;
          53                }
          54                else
          55                {
          56                    Alert.show("Upload successfully");
          57                    filename.text = null ;
          58                    fileList = null ;
          59                    upup.visible = false ;
          60                    init();
          61                }
          62            }
          63            
          64            private function broswe(event:Event):void
          65            {
          66                fileReferenceList.browse(filterArray) ;
          67            }
          68        ]]>
          69    </mx:Script>
          70    <mx:Button x="219" y="113" id="broswer" label="瀏覽…" fontSize="12"/>
          71    <mx:TextInput x="51" editable="{editable}" y="114" id="filename" />
          72    <mx:Button label="上傳" id="upup" visible="false" horizontalCenter="119" verticalCenter="-26" fontSize="12"/>
          73</mx:Canvas>
          74


          后臺數據處理使用PHP,代碼很簡單

          1<?
          2$up_dir = "D:\\www\\tmp\\" ;
          3move_uploaded_file($_FILES["Filedata"]['tmp_name'],$up_dir.$_FILES['Filedata']['name']) ;
          4?>


          打算加入自定義過濾屬性,現在寫死了,呵呵。
          主站蜘蛛池模板: 同心县| 河源市| 徐水县| 志丹县| 泽普县| 奉节县| 洛扎县| 留坝县| 宁武县| 虎林市| 新野县| 乐昌市| 信宜市| 安福县| 封开县| 大港区| 瓮安县| 山西省| 张家川| 镇江市| 岐山县| 吉木萨尔县| 皮山县| 抚松县| 金门县| 绥江县| 乃东县| 尼勒克县| 花莲市| 玉田县| 赤城县| 乳源| 紫阳县| 固安县| 泾阳县| 乐昌市| 建湖县| 长子县| 临桂县| 永清县| 荔波县|