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.');
            } 
        });
    });
    复制代码

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

  • 相关阅读:
    linux环境变量(一)
    linux常用命令-ps
    linux实用小命令--查看文本内容
    postman tests常用方法
    Vue 中嵌套 Iframe,用postMessage通信 踩坑记
    [Vue warn]: Error in nextTick: "RangeError: Maximum call stack size exceeded"
    对STM32所用位带操作宏的详细剖析
    移植Modbus TCP二
    移植Modbus TCP一
    STM32位带操作
  • 原文地址:https://www.cnblogs.com/zxtceq/p/7356065.html
Copyright © 2011-2022 走看看