zoukankan      html  css  js  c++  java
  • 3.2版uploadify详细例子(含FF和IE SESSION问题)

    最近做项目中碰到上传需要显示进度的问题,通过uploadfiy很好的解决了这个问题不过(IE9出现了按钮不能点击的问题,至今仍找不到良策)

    在使用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;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
  • 相关阅读:
    Android OpenGL ES 2.0 (四) 灯光perfragment lighting
    Android OpenGL ES 2.0 (五) 添加材质
    冒泡排序函数
    javascript object 转换为 json格式 toJSONString
    Liunx CentOS 下载地址
    jquery 图片切换特效 鼠标点击左右按钮焦点图切换滚动
    javascript 解析csv 的function
    mysql Innodb Shutdown completed; log sequence number解决办法
    Centos 添加 yum
    javascript 键值转换
  • 原文地址:https://www.cnblogs.com/akingyao/p/2670794.html
Copyright © 2011-2022 走看看