.net:上传图片并将保存至指定目录下(支持PC端和移动端)


页面:

<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 "未选择图片!";
  }
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM