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

    xiaoxiao2021-04-11  40

    使用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; } } }
    转载请注明原文地址: https://ju.6miu.com/read-666972.html

    最新回复(0)