首页 > 代码库 > 3.2版uploadify详细例子(含FF和IE SESSION问题)
3.2版uploadify详细例子(含FF和IE SESSION问题)
在使用uploadfiy3.2版本时需要下载jquery.tmpl.min.js并引用在Jquery下面
$("#uploadify").uploadify({ ‘uploader‘: ‘/LZKS/Handler/BigFileUpLoadHandler.ashx‘, ‘swf‘: ‘/LZKS/Scripts/uploadify/uploadify.swf‘, ‘cancelImage‘: ‘/LZKS/Scripts/uploadify/cancel.png‘, ‘queueID‘: ‘fileQueue‘, //‘auto‘: false, ‘multi‘: true, ‘buttonText‘: ‘文件上传‘, ‘formData‘: { ‘ASPSESSID‘: ASPSESSID, ‘AUTHID‘: auth }, ‘onSelect‘: function (file) { $(‘#uploadify‘).uploadifySettings(‘formData‘, { ‘ASPSESSID‘: ASPSESSID, ‘AUTHID‘: auth }); alert(formDate); }, ‘onComplete‘: function (file, data, response) { }, ‘onQueueComplete‘: function () { alert("上传完成!"); $(‘#fileQueue‘).attr(‘style‘, ‘visibility :hidden‘); }, ‘onSelectError‘: function (file, errorCode, errorMsg) { $(‘#fileQueue‘).attr(‘style‘, ‘visibility :hidden‘); }, ‘onUploadStart‘: function (file) { $(‘#fileQueue‘).attr(‘style‘, ‘top:200px;left:400px;width:400px;height :400px;visibility :visible‘); } }); });
用uplodify上传还有一个小问题就是在FF下session将会出现丢失的情况 ,在Gobal中加入如下代码来将上传过程中定义的session传至服务器上
protected void Application_BeginRequest(object sender, EventArgs e) { /* we guess at this point session is not already retrieved by application so we recreate cookie with the session id... */ try { string session_param_name = "ASPSESSID"; string session_cookie_name = "ASP.NET_SessionId"; if (HttpContext.Current.Request.Form[session_param_name] != null) { UpdateCookie(session_cookie_name, HttpContext.Current.Request.Form[session_param_name]); } else if (HttpContext.Current.Request.QueryString[session_param_name] != null) { UpdateCookie(session_cookie_name, HttpContext.Current.Request.QueryString[session_param_name]); } } catch { } try { string auth_param_name = "AUTHID"; string auth_cookie_name = FormsAuthentication.FormsCookieName; if (HttpContext.Current.Request.Form[auth_param_name] != null) { UpdateCookie(auth_cookie_name, HttpContext.Current.Request.Form[auth_param_name]); } else if (HttpContext.Current.Request.QueryString[auth_param_name] != null) { UpdateCookie(auth_cookie_name, HttpContext.Current.Request.QueryString[auth_param_name]); } } catch { } } private void UpdateCookie(string cookie_name, string cookie_value) { HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(cookie_name); if (null == cookie) { cookie = new HttpCookie(cookie_name); } cookie.Value = cookie_value; HttpContext.Current.Request.Cookies.Set(cookie); }
在JS加载前面定义下面两个变量
var auth = "<% = Request.Cookies[FormsAuthentication.FormsCookieName]==null ? string.Empty : Request.Cookies[FormsAuthentication.FormsCookieName].Value %>"; var ASPSESSID = "<%= Session.SessionID %>";
Handler文件代码如下: public class BigFileUpLoadHandler : IHttpHandler, IRequiresSessionState { DALFile Fdal = new DALFile(); public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; VideoUpLoad(context, CLSOFT.Web.LZKS.Edu.Globe.filename); } public void VideoUpLoad(HttpContext context, string fileFolderName) { context.Response.Charset = "utf-8"; string aaaaaaa=context.Request.QueryString["sessionid"]; HttpPostedFile file = context.Request.Files["Filedata"]; string uploadPath = HttpContext.Current.Server.MapPath(UploadFileCommon.CreateDir(fileFolderName)); if (file != null) { if (!Directory.Exists(uploadPath)) { Directory.CreateDirectory(uploadPath); } Model.ModelFile model = new Model.ModelFile(); model.File_ID = Guid.NewGuid().ToString(); model.File_Name = file.FileName; model.File_Path = UploadFileCommon.CreateDir(fileFolderName); model.File_Size = file.ContentLength; model.File_Extension = file.FileName.Substring(file.FileName.LastIndexOf(‘.‘) + 1); model.File_Date = DateTime.Now; model.File_CurrentMan = CLSOFT.Web.LZKS.Edu.Globe.name; file.SaveAs(uploadPath + model.File_Name); List<Model.ModelFile> list = null; if (context.Session["File"] == null) { list = new List<Model.ModelFile>(); } else { list = context.Session["File"] as List<Model.ModelFile>; } list.Add(model); context.Session.Add("File", list); } else { context.Response.Write("0"); } }//这段代码的功能是将多文件的信息存到context.Session["File"] as List<Model.ModelFileModel.ModelFile>为文件信息类 //实现批量上传的信息给Session
http://blog.csdn.net/wangqiuyun/article/details/9197021
http://www.cnblogs.com/akingyao/archive/2012/09/04/2670794.html
3.2版uploadify详细例子(含FF和IE SESSION问题)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。