.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