$("#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传至服务器上
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 = "";
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