<form id="form1" name="form1" action="CheckImg" method="post" enctype="multipart/form-data">
放一个html文件上传控件
</form>
public ActionResult CheckImg(HttpPostedFileBase Files,string NameStr)
{
if (Files == null) return "";
string FileType = Files.FileName.Substring(Files.FileName.LastIndexOf(".") + 1);//取得类型
if (FileType == "gif" || FileType == "GIF" || FileType == "jpg" || FileType == "JPG" || FileType == "png" || FileType == "PNG")
{
//新的文件名
string ImgName = NameStr + DateTime.Now.ToString("yyyyMMddHHmmssfff")+"."+FileType;
Files.SaveAs(Server.MapPath("/ImgUUrl/"+ImgName));
return ImgName;
}
else
{
return "";
}
}
只是大概源码,有些需要修改
QQ群:284741060 非诚勿扰