【Layui__上传】多图上传
2021-02-08 10:17
标签:表示 文件信息 each eal adf 初始化 png serve null 【Layui__上传】多图上传 标签:表示 文件信息 each eal adf 初始化 png serve null 原文地址:https://www.cnblogs.com/kikyoqiang/p/13081327.html前端
预览图:
后台
public JsonResult UploadResult()
{
string exhibitorId = Request.Params["exhibitorId"];
string filename = "";
bool isOk = false;
foreach (string uploadFile in Request.Files)
{
HttpPostedFileBase file = Request.Files[uploadFile] as HttpPostedFileBase;
foreach (string item in System.Web.HttpContext.Current.Application["AllowPicType"].ToString().Replace("‘", "").Replace(" ", "").Split(‘,‘))
{
if (file.FileName.EndsWith(item, true, null))
{
string path = "/exhibitoupload/" + exhibitorId + "/result/";
if (!Directory.Exists(Server.MapPath(path)))
{
Directory.CreateDirectory(Server.MapPath(path));
}
//filename = path + DateTime.Now.ToString("yyyyMMddHHmmss") + new Random().Next(1000, 9999) + "." + item;
filename = path + Guid.NewGuid() + "." + item;
file.SaveAs(Server.MapPath(filename));
isOk = true;
}
}
}
AjaxResult ajaxResult = new AjaxResult();
if (isOk)
{
ajaxResult.result = 1;
ajaxResult.msg = "上传成功";
}
else
{
ajaxResult.result = 0;
ajaxResult.msg = "上传失败";
}
ajaxResult.data.Add("filename", filename);
return Json(ajaxResult, JsonRequestBehavior.AllowGet);
}