国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - ASP.NET教程 - ASP.NET MVC4 利用uploadify.js多文件上傳

ASP.NET MVC4 利用uploadify.js多文件上傳

2020-04-28 12:22Resources ASP.NET教程

本文主要介紹了ASP.NET MVC4利用uploadify.js實現多文件上傳的方法代碼。具有很好的參考價值。下面跟著小編一起來看下吧

頁面代碼:

1.引入js和css文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
 <link href="~/Scripts/uploadify/uploadify.css" rel="external nofollow" rel="stylesheet" />
 <style type="text/css">
 #upDiv {
  width: 550px;
  height: 400px;
  border: 2px solid red;
  margin-top: 30px;
  margin-left: 50px;
  float: left;
 }
 div form {
  text-align: center;
  vertical-align: middle;
 }
 h2, h3 {
  text-align: center;
  color: #00B2EE;
 }
 #upList {
  width: 900px;
  height: 400px;
  float: left;
  margin-top: 30px;
  margin-left: 50px;
  overflow-y: scroll;
  border: 2px solid red;
 }
 #filelist {
  width: 45%;
  height: 400px;
  float: left;
 }
 #lineDiv {
  width: 50px;
  height: 400px;
  float: left;
 }
 #imglist {
  width: 45%;
  height: 400px;
  float: left;
 }
 #form1 {
  margin-top: 25px;
 }
 img {
  width: 25px;
  height: 25px;
 }
 .btn {
  width: 150px;
  height: 40px;
  text-align: center;
  background-color: #b58061;
  color: white;
 }
 p {
  cursor: pointer;
 }
</style>
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script src="~/Scripts/uploadify/jquery.uploadify-3.1.js"></script>
<script type="text/javascript">
 $(function () {
  $("#myfile").uploadify({
   "auto": false,
   "swf": "../Scripts/uploadify/uploadify.swf",
   "uploader": "../Home/UploadFiles",
   "removeCompleted": false,
   "onUploadSuccess": function (file, data, response) {
   },
   "onQueueComplete": function () {
    window.location.reload();
   }
  });
  $.ajax({
   url: "/home/loadFileInfo",
   datatype: 'html',
   success: function (result) {
    $('#filelist').append(result);
   }
  });
  $.ajax({
   url: "/home/loadImgInfo",
   datatype: 'html',
   success: function (result) {
    $('#imglist').append(result);
   }
  });
 });
 //在線打開文件
 function openFile(doc) {
  try {
   var fileName = $(doc).text();
   var url = window.location.protocol + "//" + window.location.host + "/UploadFile/File/"
   url = url + fileName;
   window.open(url);
  } catch (EventException) {
   alert("此文件無法打開!");
  }
 }
 //在線打開圖片
 function openImg(doc) {
  var fileName = $(doc).text();
  var url = window.location.protocol + "//" + window.location.host + "/UploadImg/Img/"
  url = url + fileName;
  window.open(url);
 }
</script>

2.body內代碼

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  <body style="background: url(../../Images/bg.jpg) no-repeat; background-size: 1600px; width: 1600px; height: 700px; ">
 <h2 style="text-align:center;">ASP .NET MVC4 多文件文件上傳實例</h2>
 <form id="form1">
  <div>
   <input type="file" id="myfile" name="myfile" />
  </div>
  <div>
   <a class="btn" href="javascript:$('#myfile').uploadify('upload');" rel="external nofollow" >上傳第一個</a>
   <a class="btn" href="javascript:$('#myfile').uploadify('upload','*');" rel="external nofollow" >上傳隊列</a>
   <a class="btn" href="javascript:$('#myfile').uploadify('cancel');" rel="external nofollow" >取消第一個</a>
   <a class="btn" href="javascript:$('#myfile').uploadify('cancel', '*');" rel="external nofollow" >取消隊列</a>
  </div>
 </form>
 <div id="upList">
  <div id="filelist">
   <h3>文件列表</h3>
  </div>
  <div id="lineDiv"></div>
 
  <div id="imglist">
   <h3>圖片列表</h3>
  </div>
 </div>
</body>

后臺代碼:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
public ActionResult loadFileInfo()
  {
   StringBuilder sb = new StringBuilder();
   DirectoryInfo theFolder = new DirectoryInfo(Server.MapPath("~/UploadFile/"));
   DirectoryInfo[] dirInfo = theFolder.GetDirectories();
   //遍歷文件夾
   foreach (DirectoryInfo NextFolder in dirInfo)
   {
    FileInfo[] fileInfo = NextFolder.GetFiles();
    //遍歷文件
    foreach (FileInfo NextFile in fileInfo)
    {
     string exStr = NextFile.Extension;
     string str = NextFile.Name;
     if (exStr == ".zip" || exStr == ".7z" || exStr == ".rar" || exStr.ToLower() == ".rars")
     {
      sb.Append("<p onclick='openFile(this)'><img src='../../Images/zip.png' width='25' height='25' />" + str + "</p>");
     }
     else if (exStr == ".doc" || exStr == ".docx")
     {
      sb.Append("<p onclick='openFile(this)'><img src='../../Images/words.png' width='25' height='25' />" + str + "</p>");
     }
     else if (exStr == ".ppt" || exStr == ".pptx")
     {
      sb.Append("<p onclick='openFile(this)'><img src='../../Images/ppt.jpg' width='25' height='25' />" + str + "</p>");
     }
     else if (exStr == ".xlsx" || exStr == ".xls" || exStr == ".XLS")
     {
      sb.Append("<p onclick='openFile(this)'><img src='../../Images/excel.png' width='25' height='25' />" + str + "</p>");
     }
     else if (exStr == ".pdf")
     {
      sb.Append("<p onclick='openFile(this)'><img src='../../Images/pdf.jpg' width='25' height='25' />" + str + "</p>");
     }
     else if (exStr == ".js" || exStr == ".JS")
     {
      sb.Append("<p onclick='openFile(this)'><img src='../../Images/js.png' width='25' height='25' />" + str + "</p>");
     }
     else if (exStr == ".html" || exStr == ".HTML")
     {
      sb.Append("<p onclick='openFile(this)'><img src='../../Images/html.png' width='25' height='25' />" + str + "</p>");
     }
     else if (exStr == ".txt" || exStr == ".TXT")
     {
      sb.Append("<p onclick='openFile(this)'><img src='../../Images/txt.png' width='25' height='25' />" + str + "</p>");
     }
     else if (exStr == ".mp3" || exStr == ".wmv" || exStr == ".aac")
     {
      sb.Append("<p onclick='openFile(this)'><img src='../../Images/mp3.png' width='25' height='25' />" + str + "</p>");
     }
     else if (exStr == ".avi" || exStr == ".mov" || exStr == ".mp4" || exStr == ".ram" || exStr == ".flv")
     {
      sb.Append("<p onclick='openFile(this)'><img src='../../Images/video.png' width='25' height='25' />" + str + "</p>");
     }
     else {
      sb.Append("<p onclick='openFile(this)'><img src='../../Images/file.jpg' width='25' height='25' />" + str + "</p>");
     }
    }
   }
   return Content(sb.ToString());
  }
  public ActionResult loadImgInfo()
  {
   StringBuilder sb = new StringBuilder();
   DirectoryInfo theFolder = new DirectoryInfo(Server.MapPath("~/UploadImg/"));
   DirectoryInfo[] dirInfo = theFolder.GetDirectories();
   //遍歷文件夾
   foreach (DirectoryInfo NextFolder in dirInfo)
   {
    FileInfo[] fileInfo = NextFolder.GetFiles();
    //遍歷文件
    foreach (FileInfo NextFile in fileInfo)
    {
     string str = NextFile.Name;
     sb.Append("<p onclick='openImg(this)'><img src='../../Images/img.png' width='25' height='25' />" + str + "</p>");
    }
   }
   return Content(sb.ToString());
  }
  public ActionResult UploadFile()
  {
   string filepath = "";
   bool fileOK = false;
   //判斷是否已經選擇上傳文件
   HttpPostedFileBase file = Request.Files["myfile"];
   if (file != null && file.ContentLength > 0)
   {
    String fileExtension = System.IO.Path.GetExtension(file.FileName).ToLower();
    //判斷是否為圖片類型
    String[] allowedExtensions = { ".gif", ".png", ".bmp", ".jpg" };
    for (int i = 0; i < allowedExtensions.Length; i++)
    {
     if (fileExtension == allowedExtensions[i])
     {
      fileOK = true;
     }
    }
    if (fileOK)
    {
     //設置上傳目錄
     string path = Server.MapPath("~/UploadImg/Img/");
     if (!Directory.Exists(path))
      Directory.CreateDirectory(path);
     string filenNamer = file.FileName;
     //文件路徑
     filepath = path + filenNamer;
     file.SaveAs(filepath);
     return RedirectToAction("Upload", "Home");
    }
    else
    {
     //設置上傳目錄
     string path = Server.MapPath("~/UploadFile/File/");
     if (!Directory.Exists(path))
      Directory.CreateDirectory(path);
     //不為圖片類型的文件存入到File目錄中
     string filenNamer = file.FileName;
     //文件路徑
     filepath = path + filenNamer;
     file.SaveAs(filepath);
     return RedirectToAction("Upload", "Home");
    }
   }
   else
   {
    var script = String.Format("<script>alert('請選擇文件后再上傳!');location.href='{0}'</script>", Url.Action("Upload"));
    return Content(script, "text/html");
   }
  }

以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持服務器之家!

原文鏈接:http://www.cnblogs.com/Resources-blogs/p/6599236.html

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: 欧美黄色网视频 | 日本一区二区在线视频 | 亚洲国产精品久久久久久久 | 97精品国产97久久久久久粉红 | 在线第一页 | 欧美激情视频一区二区三区在线播放 | 日韩一区二区三区在线看 | 91在线观看| 国产97在线 | 亚洲 | 毛片免费观看 | 欧美日韩精品久久久免费观看 | 99视频在线免费观看 | 久久av网 | 最近日本韩国高清免费观看 | 久热免费在线观看 | 色网网站 | 国产中文字幕在线观看 | 亚洲免费成人在线视频 | 黄色片在线 | 欧美精品一区二区三区在线播放 | 欧美在线a| 日本a在线| 精品国产青草久久久久福利 | 久草青青| 久久久国产一区二区三区 | 一区二区在线不卡 | 亚洲a在线播放 | 中文字幕 亚洲一区 | 日韩在线精品 | 亚洲国产中文字幕 | 国产精品自拍视频 | 成人欧美 | 日韩中文字幕一区二区高清99 | 国产福利一区二区 | 亚洲 欧美 国产 制服 动漫 | 伊人激情影院 | 中文字幕一区在线观看视频 | 欧美精品在线一区二区三区 | 黄色av大片在线观看 | 成人精品一区二区三区 | 中文字幕第一页在线 |