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

来源:互联网 发布:nba球员场均数据排名 编辑:程序博客网 时间:2024/05/22 04:49

使用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;            }        }    }



0 0
原创粉丝点击