CFupdateアップロードコントロールの使用

88517 ワード

同僚が探していたこのコントロールはいいと思います。公式(http://www.access2008.cn/)にソースをダウンロードしてから少し修正してください。
htmlページコード:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh_cn" lang="zh_cn">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>       </title>

</head>

<body bgcolor="#ffffff" style="text-align:center;">



  <!--       URL-->

  <!--        -->

  <!-- saved from url=(0013)about:internet -->

  <script language="javascript">

function challs_flash_update(){ //Flash      

    var a={};

    //     Object   



    a.title = "    "; //        

    

    a.FormName = "Filedata";

    //  Form       Name  



    a.url = "ImgHandler.aspx"; 

    //           

    

    a.parameter = ""; 

    //      , GET    , :"key=value&key=value&..."

    

    a.typefile = ["Images (*.gif,*.png,*.jpg,*jpeg)","*.gif;*.png;*.jpg;*.jpeg;",

                "GIF (*.gif)","*.gif;",

                "PNG (*.png)","*.png;",

                "JPEG (*.jpg,*.jpeg)","*.jpg;*.jpeg;"];

    //           

    //a.typefile = ["File (*.rar,*.doc,*.zip,*.txt,*.docx,*.swf,*.html,*.htm)", "*.rar;*.doc;*.zip;*.txt;*.docx;*.swf;*.html;*.htm"];

    //             

    //"Images (*.gif,*.png,*.jpg)"                      ,

    //"*.gif;*.png;*.jpg"        ,                     Windows     ,     

    //2    ,          

    

    a.newTypeFile = ["Images (*.gif,*.png,*.jpg,*jpeg)","*.gif;*.png;*.jpg;*.jpeg;","JPE;JPEG;JPG;GIF;PNG",

                "GIF (*.gif)","*.gif;","GIF",

                "PNG (*.png)","*.png;","PNG",

                "JPEG (*.jpg,*.jpeg)","*.jpg;*.jpeg;","JPE;JPEG;JPG"];

    //        ,                   ,      ,typefile   

    //"Images (*.gif,*.png,*.jpg)"                      ,

    //"*.gif;*.png;*.jpg"        ,                     Windows     ,     

    //"JPE;JPEG;JPG;GIF;PNG"       Macintosh       ,         :"JPEG;jp2_;GI

    

    a.UpSize = 0;

    //          ,0       ,  MB

    

    a.fileNum = 10;

    //          ,0       

    

    a.size = 1;

    //          ,  MB,        

    

    //a.FormID = ['select','select2'];

    //           ID      POST        

    //     FORM   checkbox,text,textarea,radio,select   ID ,radio        ID  

    //       ,           challs_flash_FormData()     

    

    a.autoClose = 1;

    //      ,           ,      ,     ,    -1        ,  :   CompleteClose false   

    

    a.CompleteClose = true;

    //   true ,       ,          ,     UpSize    ,    false

    

    a.repeatFile = true;

    //   true ,               ,                  ,   false

    

    a.returnServer = true;

    //   true ,                       ,            ,        ,   false

    

    a.MD5File = 0;

    //  MD5      ,     ,  :FLASH      100M   ,       ,    0

    //0   MD5    

    //1     MD5     

    //2     ,          ,                 

    //3          ,       ,  MD5         ,      MD5  ,   ,      ,        ,           

    

    a.loadFileOrder=true;

    //             ,TRUE =     ,FALSE =     

    

    a.mixFileNum=0;

    //         ,                 (           )      ,      ,0    

    

    a.ListShowType = 2;

    //        :1 =       ,2 =        (         )

    

    a.InfoDownRight = "";

    //            ,     %1% =            ,%2% =            ,  “    :%1%      :%2% ”

    

    a.TitleSwitch = true;

    //        

    

    a.ForceFileNum = 0;

    //      ,                  (          ),      , 0    ,     mixFileNum,autoClose fileNum     !

    

    a.autoUpload = false;

    //   true ,       ,      ,      ,   false;

    

    a.adjustOrder = true;

    //   true ,        ,      

    

    a.deleteAllShow = true

    //

     

    a.language = 0; 

    //     ,0      1     ,2      3   

    

    a.countData = true;

    //                   ,POST      

    //access2008_box_info_max      

    //access2008_box_info_upload      (        )

    //access2008_box_info_over          (         )

    

    a.isShowUploadButton = true;

    //        ,   true

    

    return a ;

    //  Object

}



function challs_flash_onComplete(a){ //           ,     Object    ,          ,  ,      ,    

    var name=a.fileName; //       

    var size=a.fileSize; //

    var time=a.updateTime; //             

    var type=a.fileType; //      ,  Windows  ,         。   Macintosh  ,                

    //document.getElementById('show').innerHTML+=name+' --- '+size+'   ----    :'+type+'---    '+(time/1000)+' <br><br>'

}



function challs_flash_onCompleteData(a){ //           

    //document.getElementById('show').innerHTML+='<font color="#ff0000">        :</font><br />'+a+'<br />';    

}

function challs_flash_onStart(a){ //             ,     Object    ,          ,  ,  

    var name=a.fileName; //       

    var size=a.fileSize; //

    var type=a.fileType; //      ,  Windows  ,         。   Macintosh  ,                

    //document.getElementById('show').innerHTML+=name+'    !<br />';

    

    return true; //   false  ,        

}



function challs_flash_onStatistics(a){ //                   ,   a     

    var uploadFile = a.uploadFile; //      

    var overFile = a.overFile; //      

    var errFile = a.errFile; //      

}



function challs_flash_alert(a){ //    ,          ,   a      

    //document.getElementById('show').innerHTML+='<font color="#ff0000">    :</font>'+a+'<br />';

}



function challs_flash_onCompleteAll(a){ //              ,   a     ,         

    document.getElementById('show').innerHTML+='<font color="#ff0000">        ,</font>    '+a+' !<br />';

    //window.location.href = 'http://www.baidu.com'; //     ,    

}



function challs_flash_onSelectFile(a){ //            ,   a     ,          

    //document.getElementById('show').innerHTML+='<font color="#ff0000">      :</font>      '+a+' !<br />';

}



function challs_flash_deleteAllFiles(){ //



    //   true   ,false    

    return confirm("         ?");

}



function challs_flash_onError(a){ //          ,     Object    ,         ,  ,  

    var err=a.textErr; //    

    var name=a.fileName; //       

    var size=a.fileSize; //

    var type=a.fileType; //      ,  Windows  ,         。   Macintosh  ,                

    document.getElementById('show').innerHTML+='<font color="#ff0000">'+name+' - '+err+'</font><br />';

}



function challs_flash_FormData(a){ //   FormID       

    try{

        var value = '';

        var id=document.getElementById(a);

        if(id.type == 'radio'){

            var name = document.getElementsByName(id.name);

            for(var i = 0;i<name.length;i++){

                if(name[i].checked){

                    value = name[i].value;

                }

            }

        }else if(id.type == 'checkbox'){

            var name = document.getElementsByName(id.name);

            for(var i = 0;i<name.length;i++){

                if(name[i].checked){

                    if(i>0) value+=",";

                    value += name[i].value;

                }

            }

        }else if(id.type == 'select-multiple'){

            for(var i=0;i<id.length;i++){

                if(id.options[i].selected){

                    if(i>0) value+=",";

                     values += id.options[i].value; 

                }

            }

        }else{

            value = id.value;

        }

        return value;

     }catch(e){

        return '';

     }

}



function challs_flash_style(){ //          

    var a = {};

    

    /*           */

    a.backgroundColor=['#f6f6f6','#f3f8fd','#dbe5f1'];    //    ,3       

    a.backgroundLineColor='#5576b8';                    //        

    a.backgroundFontColor='#066AD1';                    //          

    a.backgroundInsideColor='#FFFFFF';                    //        

    a.backgroundInsideLineColor=['#e5edf5','#34629e'];    //       ,2       

    a.upBackgroundColor='#ffffff';                        //          

    a.upOutColor='#000000';                                //               

    a.upOverColor='#FF0000';                            //                

    a.downBackgroundColor='#ffffff';                    //          

    a.downOutColor='#000000';                            //               

    a.downOverColor='#FF0000';                            //                 

    

    /*         */

    a.Top_backgroundColor=['#e0eaf4','#bcd1ea'];         //    ,    ,2       

    a.Top_fontColor='#245891';                            //      

    

    

    /*         */

    a.button_overColor=['#FBDAB5','#f3840d'];            //           ,2       

    a.button_overLineColor='#e77702';                    //           

    a.button_overFontColor='#ffffff';                    //           

    a.button_outColor=['#ffffff','#dde8fe'];             //          ,2       

    a.button_outLineColor='#91bdef';                    //          

    a.button_outFontColor='#245891';                    //          

    

    /*        */

    a.List_scrollBarColor="#000000"                        //       

    a.List_backgroundColor='#EAF0F8';                    //     

    a.List_fontColor='#333333';                            //      

    a.List_LineColor='#B3CDF1';                            //       

    a.List_cancelOverFontColor='#ff0000';                //            

    a.List_cancelOutFontColor='#D76500';                //           

    a.List_progressBarLineColor='#B3CDF1';                //        

    a.List_progressBarBackgroundColor='#D8E6F7';        //           

    a.List_progressBarColor=['#FFCC00','#FFFF00'];        //       ,2       

    

    /*         */

    a.Err_backgroundColor='#C0D3EB';                    //      

    a.Err_fontColor='#245891';                            //       

    a.Err_shadowColor='#000000';                        //       

    

    

    return a;

}





var isMSIE = (navigator.appName == "Microsoft Internet Explorer");   

function thisMovie(movieName){   

  if(isMSIE){   

      return window[movieName];   

  }else{

      return document[movieName];   

  }   

}

</script>

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="500" height="400" id="update" align="middle">

<param name="allowFullScreen" value="false" />

    <param name="allowScriptAccess" value="always" />

    <param name="movie" value="update.swf" />

    <param name="quality" value="high" />

    <param name="bgcolor" value="#ffffff" />

    <embed src="update.swf" quality="high" bgcolor="#ffffff" width="500" height="400" name="update" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />

    </object>

<div id="show" style="margin-top:20px; width:500px; text-align:left;"></div>

</body>

</html>
処理ファイルのaspxページ:
 
protected void Page_Load(object sender, EventArgs e)

        {

            //---------------------------------------------------------------------------------------------

            //    a.MD5File 2,3       



            if (Request.QueryString["access2008_cmd"] != null && Request.QueryString["access2008_cmd"] == "2")//     MD5            

            {

                //  Request.QueryString["access2008_File_name"];    //   

                //  Request.QueryString["access2008_File_size"];    ////  Request.QueryString["access2008_File_type"];    //       .gif .png

                //  Request.QueryString["access2008_File_md5"];     //   MD5  



                Response.Write("0");//      0 =       , 2 =      ,          

                Response.End();

            }

            else if (Request.QueryString["access2008_cmd"] != null && Request.QueryString["access2008_cmd"] == "3") //             

            {

                //  Request.QueryString["access2008_File_name"];    //   

                //  Request.QueryString["access2008_File_size"];    ////  Request.QueryString["access2008_File_type"];    //       .gif .png



                Response.Write("1");//     0 =       ,1 =   MD5            , 2 =      ,          

                Response.End();

            }

            //---------------------------------------------------------------------------------------------



            if (Request.Files["Filedata"] != null)//           

            {

                SaveImages("File/");

                //        



                if (Request.QueryString["access2008_File_md5"] != null)

                {

                    Response.Write("<br/>");

                    Response.Write("MD5  " + Request.QueryString["access2008_File_md5"]);

                }

                Response.Write("<br/>");

                Response.Write("     <font color='#ff0000'>" + Request.Form["select"] + "</font>--<font color='#0000ff'>" + Request.Form["select2"] + "</font>");

                Response.End();

            }





        }



        #region     

        /// <summary>

        ///     

        /// </summary>

        /// <param name="url">    ,      </param>

        /// <returns></returns>

        private void SaveImages(string url)

        {

            ///'  File    

            HttpFileCollection files = HttpContext.Current.Request.Files;



            ///'        

            //HttpPostedFile postedFile = files[iFile];

            HttpPostedFile postedFile = Request.Files["Filedata"]; //       

            string fileName, fileExtension, filesize;

            fileName = System.IO.Path.GetFileName(postedFile.FileName.ToString()); //     

            filesize = System.IO.Path.GetFileName(postedFile.ContentLength.ToString()); //      

            if (fileName != "")

            {

                fileExtension = System.IO.Path.GetExtension(fileName);//'     

                string NewsName = "File_" + DateTime.Now.ToString("yyyyMMddHHmmss");

                fileName = NewsName + fileExtension;

                //  :                 。

                postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath(url) + fileName);

            }



            Response.Write(fileName + "    ");

        }



        #endregion
注意しなければならないのはudate.swf表示ページは同じレベルのディレクトリの下で必要です。そうでなければ、Error來2038エラーを報告します。
その中のMD 5は、それぞれのファイルのMD 5署名が唯一であり、ファイルをアップロードすることが多い時、サーバーにアップロードしなくてもいいです。直接にサーバーにこのファイルがあるかどうかを検出して、直接に完成して、一つのタグだけを作って、シャットダウンすることを提案しています。
ソースコード外部チェーンアドレス:http://sdrv.ms/Uf2RVg