zoukankan      html  css  js  c++  java
  • uploadify学习笔记

      1 $("#fileUpload1").uploadify({
      2         'swf': '../../Front/Common/Script/uploadify/uploadify.swf', //插件中.swf文件路径
      3         'uploader': '../../Front/Service/DemoService.ashx?method=UploadFile', //上传文件对应的服务器处理脚本路径
      4         //'cancelImg': '../../Common/Script/uploadify/uploadify-cancel.png', //取消按钮图片
      5         'progressData': 'speed', //'speed'or'percentage'
      6         //'fileSizeLimit': '50MB', //文件大小限制
      7         'formData': { 'type': '2' }, //前台传递给后台的参数
      8         'queueSizeLimit': 999, //最大上传队列数量
      9         'uploadLimit': 999, //最大上传文件数量
     10         'queueID': 'fileList', //上传队列绑定的控件id
     11         'fileTypeDesc': 'zip,rar', //可上传文件类型描述
     12         'fileTypeExts': '*.zip;*.rar', //可上传文件类型
     13         'buttonText': '添付', //按钮文本
     14         'method': 'post', //请求方式:'post' or 'get'
     15         'requeueErrors': 'false', //上传过程中因为出错导致失败的文件是否重新加入队列
     16         'removeCompleted': true, //是否移除上传完成队列
     17         'wmode': 'transparent', //设置背景是否透明
     18         'auto': true, //选中文件后自动上传
     19         'multi': true, //是否可以同时上传多个文件
     20         'width': 48, //设置按钮宽度
     21         'height': 18, //设置按钮高度
     22         'overrideEvents': ['onSelectError'],
     23         'onCancel': function(file) {
     24         },
     25         'onUploadError': function(file, errorCode, errorMsg, errorString) {
     26         },
     27         'onUploadStart': function(file) {
     28         },
     29         'onClearQueue': function(queueItemCount) {
     30         },
     31         'onDialogClose': function(queueData) {
     32         },
     33         //文件选择事件
     34         'onSelect': function(file) {
     35 
     36         },
     37         //文件选择错误
     38         'onSelectError': function(file, errorCode, errorMsg) {
     39         },
     40         //文件上传成功的处理方法
     41         'onUploadSuccess': function(file, data, response) {
     42             var result = data.split(",");
     43             $("#file").val(result[2]);
     44             $("#file").attr("title", result[2]);
     45         },
     46         //在队列中的文件上传完成后触发
     47         'onQueueComplete': function(queueData) {
     48         }
     49     });
     50 });
     51 
     52 后台处理:
     53  #region 上传文件
     54        
     55         /// 提供功能  :1.保存文件 2.保存文件信息 3.返回文件id
     56         /// 目的      :保存文件并返回文件id
     57         /// 返回值    :文件名 文件保存路径 文件相对路径 文件id
     58         public void UploadFile()
     59         {
     60             HttpPostedFile file = contextA.Request.Files["Filedata"];//获取上传文件数据
     61             string employeeCode = contextA.Request["employeeCode"];//作成者code
     62             string formFlag = contextA.Request["employeeName"];//标识不同页面的formFlag
     63             // string formName = "申请";//默认页面名称
     64             // formName = GetFormNameByFormFlag(formFlag);
     65            // string type = contextA.Request["type"];//作成者code
     66            // string formName = "Pictures";//默认页面名称
     67             //formName = GetFormNameByFormFlag(type);
     68             string attachmentId = "";//文件id
     69             string uploadPath = System.AppDomain.CurrentDomain.BaseDirectory + "FileData\software\Files";
     70             // string uploadPath = System.AppDomain.CurrentDomain.BaseDirectory + "FileData\software";
     71             if (file != null)
     72             {
     73                 //string yearMonthDay = DateTime.Now.ToString("yyyyMMdd"); //年月日
     74                 //string createDate = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); //年-月-日 时:分:秒
     75                 //string fullTime = DateTime.Now.ToString("hhmmss"); //年月日时分秒
     76                 string originalFileName = file.FileName.ToString(); //原文件名
     77                 //uploadPath = uploadPath + "\" + formName + "\" + yearMonthDay + "\" + fullTime; //保存路径
     78 
     79                 //uploadPath = uploadPath + "\" + formName; //保存路径
     80 
     81                 string path = uploadPath + "\" + originalFileName; //文件保存路径
     82                 path = path.Replace("\", "\\");
     83 
     84                 string url = "FileData/software/Files/" + originalFileName;//项目相对路径
     85 
     86                 //string url = "FileData/software/" + formName + "/" + originalFileName;//项目相对路径
     87 
     88                 if (!Directory.Exists(uploadPath))
     89                 {
     90                     Directory.CreateDirectory(uploadPath); //创建相应的文件目录
     91                 }
     92                 file.SaveAs(path); //保存文件到相应的存储路径
     93                 if (File.Exists(path))
     94                 {
     95                     //获取上传文件信息插入成功后生成的id
     96                     //DataTable dt = ip.SaveAttachmentInfo(originalFileName, url, employeeCode, createDate, employeeCode, createDate, formFlag);
     97                     //attachmentId = dt.Rows[0][0].ToString();
     98                 }
     99                 //文件名转码
    100                 string message = HttpUtility.UrlEncode(originalFileName);
    101 
    102                 //将原始文件名、存储路径、相对路径、文件id返回前台
    103 
    104                 contextA.Response.Write(string.Format("{0},{1},{2},{3}", message, path, url, attachmentId));
    105             }
    106         }
    123 
    
    136 
    137 
    138       
    139         /// 提供功能  :
    140         /// 行为      :
    141         /// 目的      :删除附件
    142         /// 获取的参数:文件id、文件地址
    143         /// 返回值    :如果该附件存在返回附件名,否则返回1
    144         public void DeleteFile()
    145         {
    146             /***************** 获取前台参数 *************************/
    147             // attachmentId : 文件id
    148             // name         : 文件名称
    149             // path         : 文件地址
    150             string attachmentId = contextA.Request["attachmentId"];
    151             string name = contextA.Request["name"];
    152             string path = contextA.Request["path"];
    153             string uploadPath = System.AppDomain.CurrentDomain.BaseDirectory + "FileData\software\Files\"+ path;
    154             path = uploadPath.Replace("\", "\\");
    155             /********************************************************/
    156             if (!string.IsNullOrEmpty(name))
    157             {
    158                 if (File.Exists(path))
    159                 {
    160                     File.Delete(path);
    161                     if (!File.Exists(path))
    162                     {
    163                         //bool isSuccess = ip.DeleteAttachmentInfo(attachmentId);
    164                         //if (isSuccess)
    165                         //{
    166                         //    contextA.Response.Write("1");
    167                         //}
    168                     }
    169                     else
    170                     {
    171                         contextA.Response.Write(name);
    172                     }
    173                 }
    174                 else
    175                 {
    176                     contextA.Response.Write("1");
    177                 }
    178             }
    179             else
    180             {
    181                 contextA.Response.Write("1");
    182             }
    183         }
    184 
    185         /// 提供功能  :
    186         /// 行为      :
    187         /// 目的      :批量删除附件
    188         /// 获取的参数:文件id、文件地址
    189         /// 返回值    :如果该附件存在返回0,否则返回1
    190         public void RemoveAllUploadedFiles()
    191         {
    192             /***************** 获取前台参数 *************************/
    193             // idList   : id列表
    194             // pathList : 路径列表
    195             var idList = contextA.Request["idList"];
    196             var pathList = contextA.Request["pathList"];
    197             /***************** 获取前台参数 *************************/
    198             var isSuccess = false; //是否成功标识
    199             if (!string.IsNullOrEmpty(idList))
    200             {
    201                 //isSuccess = ip.DeleteAttachmentInfo(idList);
    202             }
    203             if (!string.IsNullOrEmpty(pathList))
    204             {
    205                 var _pathList = pathList.Split('|');
    206                 for (var i = 0; i < _pathList.Length; i++)
    207                 {
    208                     if (File.Exists(_pathList[i]))
    209                     {
    210                         File.Delete(_pathList[i]);
    211                     }
    212                 }
    213             }
    214             //此处有个特殊的处理逻辑:只要成功删除了附件表的数据,就算删除成功
    215             if (isSuccess)
    216             {
    217                 contextA.Response.Write("1"); //成功返回1
    218             }
    219             else
    220             {
    221                 contextA.Response.Write("0"); //失败返回0
    222             }
    223         }
    224         #endregion
    225 
    226 
    227 
    228 uploadify:上传文件获取路径时   
    229 var result = data.split(",");
    230 address = result[2];
  • 相关阅读:
    spring boot Jar
    通过JS判断设备类型
    JS获取本周、上月、本月、上月的开端日期、停止日期
    移动端长按删除事件
    获取浏览器的User Anent及判断微信浏览器
    jquery.range.js左右滑动选取数值插件,动态改变进度。
    JAVA 基础 /第九课: 变量 / JAVA中 什么是变量
    dva基本用法
    Generator 简介
    使用vuex的流程随笔
  • 原文地址:https://www.cnblogs.com/littleCode/p/3417830.html
Copyright © 2011-2022 走看看