zoukankan      html  css  js  c++  java
  • [ASP.NET]uploadify简单使用讲解

    背景:在用户控件中使用html 的file控件或者ASP.NET的FileUpLoad控件都无法获取到文件,于是想到听说过的uploadify

    uploadify官网:www.uploadify.com

    直接官网下载相关文件,发现里面有几个php文件,为了不用还配置php于是修改为ASP.NET用法

    添加UploadHandler.ashx文件及修改代码:

    复制代码
    public class UploadHandler : IHttpHandler
        {
    
            public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "text/plain";
                context.Response.Charset = "utf-8";
    
                HttpPostedFile file = context.Request.Files["Filedata"];
                string uploadPath =
                    HttpContext.Current.Server.MapPath(@context.Request["folder"]) + "\";
    
                if (file != null)
                {
                    if (!Directory.Exists(uploadPath))
                    {
                        Directory.CreateDirectory(uploadPath);
                    }
                    file.SaveAs(uploadPath + file.FileName);
                    //下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失
                    context.Response.Write("1");
                }
                else
                {
                    context.Response.Write("0");
                }
            }
    复制代码

    在ascx页面引入3.1版本的uploadify

    <link rel="stylesheet" type="text/css" href="../jslib/uploadify/uploadify.css" />
    <script type="text/javascript" src="../jslib/uploadify/jquery-1.7.2.min.js"></script>//uploadify官网说明1.7.2+,既然推荐1.7.2那就是这个版本
    <script type="text/javascript" src="../jslib/uploadify/jquery.uploadify.min.js"></script>

    在加入js

    复制代码
    $(function() {
        $('#ftcFormHolder_FpgForm_btnHtmlFile1').uploadify({
            'swf'      : '../jslib/uploadify/uploadify.swf',
            'uploader' : '../jslib/uploadify/UploadHandler.ashx', 
            'buttonText': '浏览',
            'multi': false,
            'onUploadComplete' : function(file) {
                alert('The file ' + file.name + ' finished processing.');
            } 
        });
    });
    复制代码

    以上为简单使用,其他参数或者事件可参考官网

  • 相关阅读:
    RSA算法
    Windows-caffe配置
    python 下 excel,csv 文件的读写
    python 网络通讯 服务器端代码demo,能够同时处理多个客户端的连接请求
    python 下串口数据的读取,解析,和保存-
    XML字符串和JAVA对象之间的转化
    MySQL的join on和 where 的执行顺序和区别,以及各种连接说明
    全国各行政区行政编码
    计数器+打卡+习惯+目标APP推荐
    安卓计数器类APP推荐
  • 原文地址:https://www.cnblogs.com/zxtceq/p/7356065.html
Copyright © 2011-2022 走看看