public ActionResult UpLoad()
{
HttpFileCollectionBase fils = Request.Files;//得到上传过来的文件
if (fils.Count > 0)
{
//文件字节长度
if (fils[0].ContentLength > 0)
{
//2.0上传图片或要将图片的名称做一个修改(不能重复)
string oldName = fils[0].FileName;
//得到当前文件名称后缀
string exName = Path.GetFileName(oldName);
//生成一个永不重复的名称
string newName = Guid.NewGuid() + exName;
using (System.Drawing.Image img = System.Drawing.Image.FromStream(fils[0].InputStream))
{
img.Save(Server.MapPath("/img/") + newName);
return Content("OK");
}
}
else
{
//上传失败
return Content("ON");
}
}
else
{
//未选择数据
return Content("未选择数据");
}
}