HttpPostedFileBase logo = Request.Files["txtlogo"];//从前台获取图片属性
if (logo.ContentLength != 0)
{
string name = logo.FileName;
//获取后缀名 ToLower转换成小写
string logojpg = Path.GetExtension(name).ToLower();
if (logojpg != ".jpg" && logojpg != ".png" && logo.ContentLength>0)
{
return Json(new { state = false });
}
//获取路径
string path = Server.MapPath("../imgs/");
//生成新的文件名
string guid = System.Guid.NewGuid().ToString();
string newName = guid + logojpg;
//保存文件
logo.SaveAs(path + newName);
model.Logo = newName;
}