Asp.net上传文件jquery.fileupload.js

版权声明:欢迎转载,转载请标明原文作者和链接。 如对您有帮助,不胜荣幸,同时也求高人指点 https://blog.csdn.net/a770kfof/article/details/70158434

使用jquery.fileupload.js上传

HTML 代码:

  <span>选择文件</span>
                                <input type="file" id="SubmitModel" name="imgPath"/>




JS  代码

         $("#SubmitModel").fileupload({
                url: "UpLoaded.ashx?Type=0&UU2ID=" + UUID,
                done: function (e, result1) {
                    if (result1.result.split('.')[0] == "false") {
                        alert(result1.result.split('.')[1]);
                    }
                    else {
                        document.getElementById("picName").innerHTML = result1.result.split('.')[1] + "." + result1.result.split('.')[2];
                     
                    }
                }
            });

定义ashx:
   public class UpLoaded : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string Power = context.Request["Type"];
            string UUID = context.Request["UU2ID"]; 
            HttpPostedFile MyFile = context.Request.Files[0];
            string[] Mystr = MyFile.FileName.Split('.');
            if (MyFile == null || Mystr.Length < 1 )
            {
                context.Response.Write("false.未知错误!");
                return;
            }
           
                if (Mystr[1] != "jpg" && Mystr[1] != "png")
                {
                    context.Response.Write("false.模型文件类型错误");
                    return;
                }
                string MdoelPath = context.Server.MapPath("~/StreamingAssets/Cache/Modele/");
                if (!Directory.Exists(MdoelPath))//如果不存在就创建file文件夹
                {
                    Directory.CreateDirectory(MdoelPath);
                }
                else
                {
                    DirectoryInfo folder = new DirectoryInfo(MdoelPath);
                    if (folder.Exists)  
                    {
                        folder.Delete(true);
                    }
                    Directory.CreateDirectory(MdoelPath);
                }
                MyFile.SaveAs(MdoelPath + MyFile.FileName);
                context.Response.Write("true."+MyFile.FileName);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }



展开阅读全文

没有更多推荐了,返回首页