• C#文件上传


     //var fileName = System.IO.Path.GetFileName(upload.FileName);
                //var filePhysicalPath = Server.MapPath("~/Content/" + fileName);//我把它保存在网站根目录的 upload 文件夹
                var fileName = Path.Combine(Request.MapPath("~/Content"),
                   Path.GetFileName(upload.FileName));
                upload.SaveAs(fileName);

                var url = "/Content/" + upload.FileName;
                var CKEditorFuncNum = System.Web.HttpContext.Current.Request["CKEditorFuncNum"];

                //上传成功后,我们还需要通过以下的一个脚本把图片返回到第一个tab选项
                return Content("<script>window.parent.CKEDITOR.tools.callFunction(" + CKEditorFuncNum + ", "" + url + "");</script>");
          

     string fileExt = postFile.FileName.Substring(postFile.FileName.LastIndexOf(".") + 1); //文件扩展名,不含“.”
                        string newFileName = DateTime.Now.ToString("yyyyMMddHHmmssffff") + "." + fileExt; //随机生成新的文件名
                        string upLoadPath = "~/Picture/"; //上传目录相对路径
                        string fullUpLoadPath = Server.MapPath(upLoadPath);  //将路径转换成 物理路径
                        string newFilePath = upLoadPath + newFileName; //上传后的路径
                        postFile.SaveAs(fullUpLoadPath + newFileName);  //核心方法
                        return Json(new { success=true, message="", remark= "/Picture/" + newFileName });

  • 相关阅读:
    shiro的授权与认证
    spring-aop
    GC选择之串行收集与并行收集
    4. Tomcat调优
    spring boot 启动 开启注解 加载 bean
    一、JavaScript实现AJAX(只需四步)
    DVWA安装
    CTF入门指南
    Metasploit 学习
    JSP笔记
  • 原文地址:https://www.cnblogs.com/ruiyuan/p/11404314.html
Copyright © 2020-2023  润新知