uploadify批量上传文件完整使用教程,供大家参考,具体内容如下
1.首先准备uploadify的js文件,网上一搜一大堆
2.上传页面UpFilePage.aspx
关键代码:
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>上传文件</title> <link href="/jquery.uploadify/uploadify.css" rel="stylesheet" /> <script type="text/javascript" src="/UploadFiles/2021-04-02/jquery-1.8.3.min.js">后台的GetFile()方法:
/// <summary> /// 获取cookie附件信息 /// </summary> /// <returns></returns> protected string GetFile() { #region 获取cookie附件信息 StringBuilder strHtml = new StringBuilder(); HttpCookie fileCookie = Request.Cookies["FileCookie"]; if (fileCookie != null) { string[] fileArray = new string[1]; if (fileCookie.Value.Contains("|")) fileArray = fileCookie.Value.Split('|'); else fileArray[0] = fileCookie.Value; foreach (string objFile in fileArray) { if (!string.IsNullOrEmpty(objFile) && objFile.Contains(",")) { string[] file = objFile.Split(','); strHtml.Append(@"<div class='uploadifyQueueItem'>"); strHtml.Append(@"<div class='cancel'>"); strHtml.Append("<a href='javascript:deleteFile(\"" + file[1] + "\")'></a>"); //strHtml.Append(@"<img src='/Scripts/jquery.uploadify/cancel.png' border='0'>"); strHtml.Append(@"</div>"); strHtml.Append(@"<span class='fileName'>" + HttpUtility.UrlDecode(file[0]) + "</span><span class='percentage'> - 100%</span><div class='uploadifyProgress'>"); strHtml.Append(@"<div class='uploadifyProgressBar' style='width: 100%;'>"); strHtml.Append(@"</div>"); strHtml.Append(@"</div>"); strHtml.Append(@"</div>"); } } } return strHtml.ToString(); #endregion }3.UploadAction文件夹下的一般处理程序:
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string operate = context.Request["operate"]; if (operate == "deleteFile") { #region 删除文件附件信息 //获取文件路径 string filePath = context.Server.MapPath(context.Request["file"]); //判断文件是否存在 if (File.Exists(filePath)) File.Delete(filePath);//删除文件 //获取附件cookie信息 HttpCookie fileCookie = context.Request.Cookies["FileCookie"]; string[] fileArray = new string[1]; if (fileCookie != null) { filePath = filePath.Remove(0, filePath.IndexOf("upfiles")).Replace("\\", "/"); if (fileCookie.Value.Contains("|")) fileArray = fileCookie.Value.Split('|'); else fileArray[0] = fileCookie.Value; string strFile = ""; for (int i = 0; i < fileArray.Length; i++) { if (!fileArray[i].Contains(filePath)) strFile += fileArray[i] + "|"; } if (strFile.Contains("|")) strFile = strFile.Remove(strFile.Length - 1); fileCookie.Value = strFile; fileCookie.Expires = DateTime.Now.AddDays(1); fileCookie.HttpOnly = true; context.Response.AppendCookie(fileCookie); StringBuilder strHtml = new StringBuilder(); if (fileCookie.Value.Contains("|")) fileArray = fileCookie.Value.Split('|'); else fileArray[0] = fileCookie.Value; foreach (string objFile in fileArray) { if (!string.IsNullOrEmpty(objFile) && objFile.Contains(",")) { string[] file = objFile.Split(','); strHtml.Append(@"<div class='uploadifyQueueItem'>"); strHtml.Append(@"<div class='cancel'>"); strHtml.Append("<a href='javascript:deleteFile(\"" + file[1] + "\")'></a>"); //strHtml.Append(@"<img src='/Scripts/jquery.uploadify-v2.1.0/cancel.png' border='0'>"); strHtml.Append(@"</div>"); strHtml.Append(@"<span class='fileName'>" + HttpUtility.UrlDecode(file[0]) + "</span><span class='percentage'> - 100%</span><div class='uploadifyProgress'>"); strHtml.Append(@"<div class='uploadifyProgressBar' style='width: 100%;'>"); strHtml.Append(@"</div>"); strHtml.Append(@"</div>"); strHtml.Append(@"</div>"); } } context.Response.Write(strHtml.ToString()); } #endregion } else if (operate == "GetFile") { #region 获取上传的附件并展示 StringBuilder strHtml = new StringBuilder(); HttpCookie fileCookie = context.Request.Cookies["FileCookie"]; if (fileCookie != null) { string[] fileArray = new string[1]; if (fileCookie.Value.Contains("|")) fileArray = fileCookie.Value.Split('|'); else fileArray[0] = fileCookie.Value; foreach (string objFile in fileArray) { if (!string.IsNullOrEmpty(objFile) && objFile.Contains(",")) { string[] file = objFile.Split(','); strHtml.Append(@"<div class='uploadifyQueueItem'>"); strHtml.Append(@"<div class='cancel'>"); strHtml.Append("<a href='javascript:deleteFile(\"" + file[1] + "\")'>"); //strHtml.Append(@"<img src='/Scripts/jquery.uploadify-v2.1.0/cancel.png' border='0'></a>"); strHtml.Append(@"</div>"); strHtml.Append(@"<span class='fileName'>" + HttpUtility.UrlDecode(file[0]) + "</span><span class='percentage'> - 100%</span><div class='uploadifyProgress'>"); strHtml.Append(@"<div class='uploadifyProgressBar' style='width: 100%;'>"); strHtml.Append(@"</div>"); strHtml.Append(@"</div>"); strHtml.Append(@"</div>"); } } } context.Response.Write(strHtml.ToString()); #endregion } }4.上传文件uploadHandler.ashx一般处理程序代码,文件上传路径可以根据剧情需要自由设定:
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; HttpCookie fileCookie = context.Request.Cookies["FileCookie"]; if (fileCookie != null) { string[] fileArray = new string[1]; if (fileCookie.Value.Contains("|")) fileArray = fileCookie.Value.Split('|'); if (fileArray.Length >= 5) return; } else { fileCookie = new HttpCookie("FileCookie"); fileCookie.Value = ""; context.Response.Cookies.Add(fileCookie); } String aspxUrl = context.Request.Path.Substring(0, context.Request.Path.LastIndexOf("/") + 1); //文件保存目录路径 String savePath = "/upfiles/"; //文件保存目录URL String saveUrl = "/upfiles/"; //if (context.Request.Cookies["Member"] != null) //{ // savePath += context.Request.Cookies["Member"]["MemberId"] + "/"; // saveUrl += context.Request.Cookies["Member"]["MemberId"] + "/"; //} string Member = Guid.NewGuid().ToString().Trim().Replace("-", ""); savePath += Member + "/"; saveUrl += Member + "/"; //定义允许上传的文件扩展名 /*Hashtable extTable = new Hashtable(); extTable.Add("image", "gif,jpg,jpeg,png,bmp"); extTable.Add("flash", "swf,flv"); extTable.Add("media", "swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb,mp4"); extTable.Add("file", "doc,docx,xls,xlsx,ppt,htm,html,txt,zip,rar,gz,bz2,swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb,mp4,wps");*/ //最大文件大小 int maxSize = 5242880; HttpPostedFile imgFile = context.Request.Files["imgFile"]; /*if (imgFile == null) { showError("请选择文件。"); }*/ String dirPath = context.Server.MapPath(savePath); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); //showError("上传目录不存在。"); } String dirName = context.Request.QueryString["dir"]; if (String.IsNullOrEmpty(dirName)) { dirName = "file"; } /*if (!extTable.ContainsKey(dirName)) { showError("目录名不正确。"); }*/ String fileName = imgFile.FileName; String fileExt = Path.GetExtension(fileName).ToLower(); /*if (String.IsNullOrEmpty(fileExt) || Array.IndexOf(((String)extTable[dirName]).Split(','), fileExt.Substring(1).ToLower()) == -1) { showError("上传文件扩展名是不允许的扩展名。\n只允许" + ((String)extTable[dirName]) + "格式。"); } if (dirName.Contains("image")) { if (imgFile.InputStream == null || imgFile.InputStream.Length > maxSize) { showError("上传文件超过5M大小限制。"); } }*/ //创建文件夹 dirPath += dirName + "/"; saveUrl += dirName + "/"; if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } String ymd = DateTime.Now.ToString("yyyyMMdd", DateTimeFormatInfo.InvariantInfo); dirPath += ymd + "/"; saveUrl += ymd + "/"; if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } String newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + fileExt; String filePath = dirPath + newFileName; imgFile.SaveAs(filePath); String fileUrl = saveUrl + newFileName; /*Hashtable hash = new Hashtable(); hash["error"] = 0; hash["url"] = fileUrl; context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8"); context.Response.Write(JsonMapper.ToJson(hash)); context.Response.End();*/ if (fileCookie != null) { string strFile = fileCookie.Value; if (!string.IsNullOrEmpty(strFile)) strFile = strFile + "|" + HttpUtility.UrlEncode(fileName) + "," + fileUrl; else strFile = HttpUtility.UrlEncode(fileName) + "," + fileUrl; fileCookie.Value = strFile; fileCookie.Expires = DateTime.Now.AddDays(1); fileCookie.HttpOnly = true; context.Response.AppendCookie(fileCookie); } context.Response.Write("1"); context.Response.End(); }5.所有代码敲完OK,可以收获成果了:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
2024年11月12日
2024年11月12日
- 雨林唱片《赏》新曲+精选集SACD版[ISO][2.3G]
- 罗大佑与OK男女合唱团.1995-再会吧!素兰【音乐工厂】【WAV+CUE】
- 草蜢.1993-宝贝对不起(国)【宝丽金】【WAV+CUE】
- 杨培安.2009-抒·情(EP)【擎天娱乐】【WAV+CUE】
- 周慧敏《EndlessDream》[WAV+CUE]
- 彭芳《纯色角3》2007[WAV+CUE]
- 江志丰2008-今生为你[豪记][WAV+CUE]
- 罗大佑1994《恋曲2000》音乐工厂[WAV+CUE][1G]
- 群星《一首歌一个故事》赵英俊某些作品重唱企划[FLAC分轨][1G]
- 群星《网易云英文歌曲播放量TOP100》[MP3][1G]
- 方大同.2024-梦想家TheDreamer【赋音乐】【FLAC分轨】
- 李慧珍.2007-爱死了【华谊兄弟】【WAV+CUE】
- 王大文.2019-国际太空站【环球】【FLAC分轨】
- 群星《2022超好听的十倍音质网络歌曲(163)》U盘音乐[WAV分轨][1.1G]
- 童丽《啼笑姻缘》头版限量编号24K金碟[低速原抓WAV+CUE][1.1G]