页面代码:
1.引入js和css文件
<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="/UploadFiles/2021-04-02/jquery-1.8.2.min.js">2.body内代码
<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>后台代码:
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"); } }以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年11月30日
2024年11月30日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]