zoukankan      html  css  js  c++  java
  • swfupload 的ASP上传示例代码

    swfupload(以下简称su)遇到的主要问题就是,版本不同造成的极大差异, 现在的版本已经到2.1beta。我用的是2.02版,天哪用的是1.xx版。

    差异具体体现在:
    lash_url : "../swfupload/swfupload_f8. swf "
    upload _url: "../multiuploaddemo/upload .php",
    function uploadSuccess(fileObj, server_data)
          如果flash_url用的是f8.swf ,那么upload _url要使用相对SWF 的路径;如果用的是f9.swf ,那么upload _url 要使用相对当前程序页面(jsp,asp )的路径,就是这点,耽误了我很长时间. 如果要使用server_data传递返回值,也必须用f9.swf ,这点也花 了我不少时间. 不管怎样,su都提供的全部源代码,有问题可以自己研究,前提是你能像我一样看的懂,呵呵.

          su使用的是flash的上传功能(Flash.net.FileReference;),还用了ActionScript 和 Flash Player 的容器之间实现直接通讯的应用程序编程接口ExternalInterface(详见后文附录),

    su超级好用,而且功能强大,可以一次上传多个文件,能在客户端检验文件类型和大小,还能在上传进度中进行控制,能在文件传完后得到后台反馈信 息,有较好的debug对话框,比如看看它的高级示例: http://demo.swfupload.org/featuresdemo/index.php 目前唯一不足的可能是对中文文件名支持不好.我研究了半天它的flash as脚本,都没弄明白中文问题怎么改.

    它的在线文档: http://demo.swfupload.org/Documentation/

    下面具体讲讲su怎么用。
    假设有一个前台页面upload .asp ,一个后 台接收文件的页面save.asp ,还有su的核心文件swfupload.js,辅助处理脚本handlers.js。
    1, 这两个js,网上的源码里就有,核心js不用改. handlers可以直接用,也可以自己写,看各人本事了.
    核心js里,主要是看SWFUpload.prototype.initSettings 初始化设置,很多参数该怎么写,可以参考它.
    2, 要在前台页面里调用这两个js,然后初始化swfu对象。 折叠展开JavaScript复制代码
    <script type="text/javascript">   
    var swfu;   
    window.onload = function () {   
        swfu = new SWFUpload({   
        // Backend Settings   
        upload _url: "upload .asp ",    // Relative to the SWF file 就是这个地方误导了我   
        file_post_name: "Filedata",  // 文件对象的名称,默认Filedata,可以自己改.后台接收就靠它识别   
        post_params: {"SESSID" : "<%=session.SessionID%>"},  // 附加参数,版本2新功能   
     
        // File Upload Settings   
        file_size_limit : "204",    // 单位kb, 限制文件大小   
        file_types : "*.jpg",  //允许的文件类型   
        file_types_description : "JPG Images", //对话框里的文件类型   
        file_upload _limit : "0",   
     
        // Event Handler Settings - these functions as defined in Handlers.js   
        //  The handlers are not part of SWFUpload but are part of my website and control how   
        //  my website reacts to the SWFUpload events.   
        //  事件处理,可以自己在handlers.js里面扩充,极大的方便了开发者   
        //  就是要在handlers里面定义如下的function,当然function里面可以什么也不干,或者用源代码自带的也行   
        file_queue_error_handler : fileQueueError,   
        file_dialog_complete_handler : fileDialogComplete,   
        upload _progress_handler : uploadProgress,   
        upload _error_handler : uploadError,   
        upload _success_handler : uploadSuccess,   
        upload _complete_handler : uploadComplete,   
     
        // Flash Settings   
        flash_url : "js/swfupload_f9.swf ",    // Relative to this file 注意是f8还是f9   
     
        custom_settings : {   
            upload _target : "divFileProgressContainer" 
        },   
           
        // Debug Settings 是否打开调试信息,默认false   
        debug: true 
        });   
    }   
    </script> 

    下面是表单的写法,无需input type=file的写法 XML/HTML复制代码
    <form> 
        <button id="btnBrowse" type="button" style="padding: 5px;" onclick="swfu.selectFiles(); this.blur();"><img src="image/page_white_add.png" style="padding-right: 3px; vertical-align: bottom;">Select Images <span style="font-size: 7pt;">(2 MB Max)</span></button> 
    </form> 
    3, 后台save.asp .
    其实如果你做过普通的文件上传,这里就很简单,不管是jsp,asp ,php,基本原理都一样. 前台swf 得到文件后,还是用post方式提交给后台,文件对象默 认名为Filedata. 比如用asp 的无组件文件上传的处理写法如下 ASP /Visual Basic复制代码
    <!--#include FILE="upload _5xsoft.inc"-->   
    <%   
    set upload =new upload _5xsoft   
    for each formName in upload .objFile   
      set file=upload .file("Filedata")     
      file.saveAs Server.mappath(file.FileName)   
      set file=nothing   
    next   
    set upload =nothing   
    response.write "ok" 
    %>   
          java里怎么处理呢? 其实也已有,比如用struts,在actionform里有一个名为Filedata的FileItem对象即可.
    php和aspx就不讲了,官方源文件就是php的例子,也有aspx的例子.

    4, 返回结果如何显示?
    比如上面第三步返回一个结果"ok". 在handlers里写上 JavaScript复制代码
    function uploadSuccess(fileObj, server_data) {   
        try {   
            document.write( server_data);   
        } catch (ex) { this.debug(ex); }   


    就这样简单.只要知道原理,你可以写出更复杂的效果.官方源代码提供了根据上传图片生成缩略图并马上显示的例子.

  • 相关阅读:
    C#对象初始化器
    C#构造方法
    C#方法重载
    C#方法
    C#类 对象 字段和属性
    C#数组
    C#字符串
    C#原码反码补码
    字段、方法、属性
    单例模式、异常
  • 原文地址:https://www.cnblogs.com/y0umer/p/3839403.html
Copyright © 2011-2022 走看看