zoukankan      html  css  js  c++  java
  • 前端提交后台一般处理文件

    <script src="../JS/jquery.form.min.js"></script>

    添加引用

      $("#form1").ajaxSubmit({
                        success: function (data) {
                           // 成功后要做的事
                        },
                        error: function (error) { alert("上传失败"); },
                        url: '../FileHelper/FileUpLoad.ashx', /*设置post提交到的页面*/
                        data: { id1: request("zjhm"), id2: request("id"), id3: "1" },//参数
                        type: "post", /*设置表单以post方法提交*/
                        dataType: "json" /*设置返回值类型为文本*/
                    });

    前端提交

    HttpPostedFile file = context.Request.Files["imgfile"];
    
                    //Thread.Sleep(3000);
    
    
    
                    //上传文件后缀名检测
                    string filename = file.FileName;
                    string suffix = Path.GetExtension(filename);
                    if (suffix != ".jpg" & suffix != ".jpeg")
                    {
                        context.Response.Write(Maticsoft.COM.Transform.ToJsonString("只允许上传jpg文件"));
                        return;
                    }
                   
    
                   
                    //重命名:DateTime
                    //Random ro = new Random();
                    filename = string.Format("{0}@{1}{2}", context.Request.Form["id1"], context.Request.Form["id2"], suffix);
    
                    if (System.IO.File.Exists(@"../photo/" + filename))
                    {
                        System.IO.File.Delete(@"../photo/" + filename);
                    }
                    //重命名:GUID(全球唯一标识符)推荐!!!
                    //filename = string.Format("{0}{1}", Guid.NewGuid().ToString("N"), suffix);
    
                    //创建目录
                    string dirPath = "";
                    string dirFullPath = context.Server.MapPath("../photo/" + dirPath);
                    string fileFullPath = Path.Combine(dirFullPath, filename);
                    //如果文件夹不存在,则先创建文件夹
                    if (!Directory.Exists(dirFullPath))
                    {
                        Directory.CreateDirectory(dirFullPath);
                    }
    
                    //string filePath = context.Server.MapPath("~/upload") + "/" + filename;
    
                    //保存文件
                    file.SaveAs(fileFullPath);
                    
                    context.Response.Write(Maticsoft.COM.Transform.ToJsonString("ok"));

    这是我上传图片的处理文件

  • 相关阅读:
    资源-python 视频下载大全
    ubuntu 16.04(操作应用) -软件卸载
    资源-简历的相关知识
    centos (命令操作)-crontab命令
    ubuntu 16.04 (软件应用)-输入法
    ntp时间同步
    lvm空间扩容
    目录知识
    Linux下安装maven
    elasticsearch安装pinyin模块
  • 原文地址:https://www.cnblogs.com/xiongyang123/p/6698917.html
Copyright © 2011-2022 走看看