zoukankan      html  css  js  c++  java
  • 上传文件-layui+ashx

     public void ProcessRequest (HttpContext context) {
            if (true) {
                context.Response.ContentType = "text/plain";
                result result = new result();
                string fileNewName  = string.Empty;
                string filePath = string.Empty;
                HttpFileCollection files = context.Request.Files;
                if (files.Count > 0)
                {
                    //设置文件名
                    fileNewName = DateTime.Now.ToString("yyyyMMddHHmmssff") + "_" + System.IO.Path.GetFileName(files[0].FileName);
                    //保存文件     
                    files[0].SaveAs(context.Server.MapPath("../Files/" + fileNewName));
                    result.code = "200";
                    result.msg = "文件上传成功!";
                }
                else {
                    result.code = "200";
                    result.msg = "文件上传失败!";
                }
                context.Response.Write(new JavaScriptSerializer().Serialize(result));
                context.Response.End();
            }
        }
        public class result{
            public string code { get; set; }
            public string msg { get; set; }
        }
     //创建上传组件
            upload.render({
                elem: '#uploadBtn',
                url: './FileOption.ashx',
                dataType:"json",
                accept: 'file', //允许上传的文件类型
                size: 0, //最大允许上传的文件大小,
                data: function () {
                    //请求上传接口的额外参数
                },
                done: function (res) {
                    if (res.code === "200") {
                        layer.msg(res.msg);
                    } else {
                        layer.msg(res.msg);
                    }
                },
                error: function () {
                    layer.msg("请求异常!"); 
                }
            });
  • 相关阅读:
    C++程序代写实现HashSet class
    EL表达式
    Hibernate的事务管理
    ThreadLocal理解
    SOA框架
    JVM垃圾回收机制
    Htpp通讯协议详解
    Android模拟器使用SD卡
    android 开发-HttpClient状态码定义
    android 开发-文件存储之读写sdcard
  • 原文地址:https://www.cnblogs.com/llljpf/p/9968436.html
Copyright © 2011-2022 走看看