日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

asp.net type=file前后台合作 在上传图片到服务器

發布時間:2025/4/14 asp.net 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 asp.net type=file前后台合作 在上传图片到服务器 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前臺

<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title> </head> <body><form runat="server" id="form1" method="post" enctype="multipart/form-data"><input name="f" type="file" /><input name="s" type="submit" /></form> </body> </html>

?

?

后臺

System.Web.HttpFileCollection _file = System.Web.HttpContext.Current.Request.Files;if (_file.Count > 0){//文件大小long size = _file[0].ContentLength;//文件類型string type = _file[0].ContentType;//文件名string name = _file[0].FileName;//文件格式string _tp = System.IO.Path.GetExtension(name);if (_tp.ToLower() == ".jpg" || _tp.ToLower() == ".jpeg" || _tp.ToLower() == ".gif" || _tp.ToLower() == ".png" || _tp.ToLower() == ".swf"){//獲取文件流System.IO.Stream stream = _file[0].InputStream;//保存文件string saveName = DateTime.Now.ToString("yyyyMMddHHmmss") + _tp;string path = DataFactory.WFile.FileUploadPath + "/upload/area/" + saveName; // string path = Server.MapPath("images/"+savename);自己編寫_file[0].SaveAs(path);}}

總結:

1.form 必須有runat="server"標記,

2.form? 必須有enctype="multipart/form-data"標記,

3.<input type="file" />的runat="server"標記可選

?

完!

?

轉載于:https://www.cnblogs.com/wwz-wwz/p/6244725.html

總結

以上是生活随笔為你收集整理的asp.net type=file前后台合作 在上传图片到服务器的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。