亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

asp.net MVC實(shí)現(xiàn)無(wú)組件上傳圖片實(shí)例介紹

 更新時(shí)間:2013年05月28日 16:55:18   作者:  
無(wú)組件實(shí)現(xiàn)上傳圖片使用input的file作為上傳選擇文件,具體實(shí)現(xiàn)如下:前后臺(tái)代碼很詳細(xì),感興趣的朋友們可不要錯(cuò)過(guò)了哈
例子:
如我想上傳一個(gè)圖片到服務(wù)器端:asp頁(yè)面
復(fù)制代碼 代碼如下:

<form id="form1" runat="server" action="/bookIndex/fileUpLoad/(你準(zhǔn)備處理的 ActionResult)" method="post" enctype="multipart/form-data">
<input type="file" id="imageUpLoad" name="imageUpLoad">
<input type="button" value="點(diǎn)擊上傳" onclick="UpLoad()">
....
</form>

js代碼:
復(fù)制代碼 代碼如下:

<script type="text/javascript">
function UpLoad()
{
如果有其他的值,判斷下是否為空.
form1.submit();
}
<script>

后臺(tái)代碼
復(fù)制代碼 代碼如下:

public ActionResult fileUpLoad(HttpPostedFileBase imageUpLoad(這里跟前臺(tái)頁(yè)面input輸入框name保持一致))
{
string fileName = imageUpLoad.FileName;
//轉(zhuǎn)換只取得文件名,去掉路徑。
if (fileName.LastIndexOf("\\") > -1)
{
fileName = fileName.Substring(fileName.LastIndexOf("\\") + 1);
}
//保存到相對(duì)路徑下。
imageUpLoad.SaveAs(Server.MapPath("../../image/img/" + fileName));
//以下代碼是將 路徑保存到數(shù)據(jù)庫(kù)。
string ImagePath = "../../image/img/" + fileName;
string sql = "insert into bookinfo(bookphoto)values('" + ImagePath + "')";
//封裝好的代碼,直接調(diào)用。
DataBase db = new DataBase();
db.getConn();
int result = db.executeUpdate(sql);
return View();
}

相關(guān)文章

最新評(píng)論