uploadify session java_3.2版uploadify详细例子(含FF和IE SESSION问题)

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

$("#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');

}

});

});

View Code

用uplodify上传还有一个小问题就是在FF下session将会出现丢失的情况 ,在Gobal中加入如下代码来将上传过程中定义的session传至服务器上

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

protected void Application_BeginRequest(objectsender, 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, stringcookie_value)

{

HttpCookie cookie=HttpContext.Current.Request.Cookies.Get(cookie_name);if (null ==cookie)

{

cookie= newHttpCookie(cookie_name);

}

cookie.Value=cookie_value;

HttpContext.Current.Request.Cookies.Set(cookie);

}

View Code

在JS加载前面定义下面两个变量

var auth = "";

var ASPSESSID = "";

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

Handler文件代码如下:public classBigFileUpLoadHandler : IHttpHandler, IRequiresSessionState

{

DALFile Fdal= newDALFile();public voidProcessRequest(HttpContext context)

{

context.Response.ContentType= "text/plain";

VideoUpLoad(context, CLSOFT.Web.LZKS.Edu.Globe.filename);

}public void VideoUpLoad(HttpContext context, stringfileFolderName)

{

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= newModel.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 list = null;if (context.Session["File"] == null)

{

list= new List();

}else{

list= context.Session["File"] as List;

}

list.Add(model);

context.Session.Add("File", list);

}else{

context.Response.Write("0");

}

}//这段代码的功能是将多文件的信息存到context.Session["File"] as List为文件信息类//实现批量上传的信息给Session

View Code

http://blog.csdn.net/wangqiuyun/article/details/9197021

http://www.cnblogs.com/akingyao/archive/2012/09/04/2670794.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值