前端:
<form action="form_action.asp" method="get">
<input type="text" size="20" name="upfile" id="Text1" style="border:1px dotted #ccc">
<input type="button" value="浏览" οnclick="path.click()" style="border:1px solid #ccc;background:#fff">
<input type="file" id="File1" style="; border:1px solid red;" οnchange="upfile.value=this.value"/>
<input type="submit" value="Submit" />
</form>
通过表单提交到后端
后端:
// 保存文件 到项目目录 images\\driverAvatar 下
HttpFileCollection files = HttpContext.Current.Request.Files;
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile postedFile = files[i];
postedFile.SaveAs(System.AppDomain.CurrentDomain.BaseDirectory + "\\images\\driverAvatar\\" + System.IO.Path.GetFileName(postedFile.FileName));
// dr.driver_phone = postedFile.FileName;
}