jquery插件uploadify使用详解

这次给大家带来jquery插件uploadify使用详解,jquery插件uploadify使用的注意事项有哪些,下面就是实战案例,一起来看一下。

有时项目中需要一个文件批量上传功能时,个人认为uploadify是快速简便的解决方案,分享给大家供大家参考,具体如下

先上效果图:

jquery插件uploadify使用详解

jquery插件uploadify使用详解

具体代码如下:

在页面中如下

jquery插件uploadify使用详解

完整页面代码

 文件批量上传Demo        $(function () {   var guid = '';   var type = '';   if (guid == null || guid == "") {    guid = newGuid();   }   if (type != null) {    type = type + '/';   }   $('#file_upload').uploadify({    'swf': 'uploadify/uploadify.swf',    //FLash文件路径    'buttonText': '浏 览',      //按钮文本    'uploader': 'uploadhandler.ashx?guid=' + guid, //处理ASHX页面    'formData': { 'folder': 'picture', 'isCover': 1 },   //传参数    'queueID': 'fileQueue',      //队列的ID    'queueSizeLimit': 10,       //队列最多可上传文件数量,默认为999    'auto': false,         //选择文件后是否自动上传,默认为true    'multi': true,         //是否为多选,默认为true    'removeCompleted': true,      //是否完成后移除序列,默认为true    'fileSizeLimit': '0',       //单个文件大小,0为无限制,可接受KB,MB,GB等单位的字符串值    'fileTypeDesc': 'All Files',     //文件描述    'fileTypeExts': '*.*',       //上传的文件后缀过滤器    'onQueueComplete': function (queueData) {  //所有队列完成后事件     alert("上传完毕!");    },    'onError': function (event, queueId, fileObj, errorObj) {     alert(errorObj.type + ":" + errorObj.info);    },    'onUploadStart': function (file) {    },    'onUploadSuccess': function (file, data, response) { //一个文件上传成功后的响应事件处理     //var data = $.parseJSON(data);//如果data是json格式     //var errMsg = "";    }   });  });  function newGuid() {   var guid = "";   for (var i = 1; i <= 32; i++) {    var n = Math.floor(Math.random() * 16.0).toString(16);    guid += n;    if ((i == 8) || (i == 12) || (i == 16) || (i == 20))     guid += "-";   }   return guid;  }  //执行上传  function doUpload() {   $('#file_upload').uploadify('upload', '*');  }    

登录后复制

UploadHandler.ashx代码:

using System;using System.Web;using System.IO;public class UploadHandler : IHttpHandler {  public void ProcessRequest (HttpContext context) {  context.Response.ContentType = "text/plain";  context.Request.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");  context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");  context.Response.Charset = "UTF-8";  if (context.Request.Files.Count > 0)  {   #region 获取上传路径   string uploadFolder = GetUploadFolder();   #endregion   if (System.IO.Directory.Exists(uploadFolder))   {//如果上传路径存在    HttpPostedFile file = context.Request.Files["Filedata"];    string filePath = Path.Combine(uploadFolder, file.FileName);    file.SaveAs(filePath);    context.Response.Write("0");   }   else   {    context.Response.Write("2");   }  } }  public bool IsReusable {  get {   return false;  } } ///  /// 返回不带后缀的文件名 ///  ///  ///  public static string GetFirstFileName(string fileName) {  return Path.GetFileNameWithoutExtension(fileName); } ///  /// 获取上传目录 ///  ///  public static string GetUploadFolder() {  string rootPath = HttpContext.Current.Server.MapPath("~");  return Path.Combine(rootPath, "test"); }}

登录后复制

文件上传.NET默认有大小限制,像IIS限制的30M默认请求大小。如果不想修改IIS,又想突破这个大小的限制,比如上传1GB大小的文件。

这是修改Web.config即可实现。

                        

登录后复制

相信看了本文案例你已经掌握了方法,更多精彩请关注【创想鸟】其它相关文章!

推荐阅读:

jQuery让浏览器相互跳转传递参数使用详解

jquery基础知识点使用详解

以上就是jquery插件uploadify使用详解的详细内容,更多请关注【创想鸟】其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2769316.html

(0)
上一篇 2025年3月8日 12:20:12
下一篇 2025年3月8日 12:20:20

AD推荐 黄金广告位招租... 更多推荐

相关推荐

发表回复

登录后才能评论