您的位置:首页 > 编程语言 > ASP

asp.net 使用layui上传

2020-07-21 04:13 1876 查看

public void Upload(HttpContext context)
{
HttpFileCollection files = context.Request.Files;
string msg = string.Empty;
string error = string.Empty;
if (files.Count > 0)
{
int id = int.Parse(context.Request.Params[“id”]);
if (id > 0)
{
var order = bll.GetModel(id);
string report_directory = HttpContext.Current.Server.MapPath("~/UploadFile/");
string report_path_root = report_directory + “\” + id.ToString() + “\”;
if (!Directory.Exists(report_directory + id.ToString()))
{
Directory.CreateDirectory(report_directory + “\” + id.ToString());
}
string guid = System.Guid.NewGuid().ToString();
string pah = System.IO.Directory.GetCurrentDirectory();
files[0].SaveAs(report_path_root + Path.GetFileName(guid));//文件保持的路径 可以使用 files[0].fileName
context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(new { code = “200”, msg = result!=“OK”?result: " 成功! 文件大小为:" + files[0].ContentLength, src = files[0].FileName }, Newtonsoft.Json.Formatting.Indented));
context.Response.End();
}
}
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: