页面:
<body>
<form id="formid" name="myform" action="Upload" method='post' enctype="multipart/form-data">
<table>
<tr>
<td>图片:</td>
<td><input type="file" name="file" accept="image/*" value="选择" /></td>
</tr>
</table>
<input type="submit" value="上传" />
</form>
</body>
后台:
public string Upload()
{
HttpPostedFileBase file = Request.Files["file"];
if (file.ContentLength > 0)
{
string savePath = Server.MapPath("~/Uploads/Pictures");
string failPath = savePath + "\\" + file.FileName;
file.SaveAs(failPath);
return “图片上传成功!”;
}
else
{
return "未选择图片!";
}
}