C#应用 uploadify 上传前判断文件是否存在
来源:互联网 发布:java往word中写入文本 编辑:程序博客网 时间:2024/06/16 06:26
原本之前使用Guid.NewGuid().ToString() 产生随机码来命名上传的文件,不用担心上传的文件重名而被覆盖。现在新的需求是要要求文件以原名存储到服务器,那么就要预防上传相同名称的文件,否则被覆盖。以下就直接上代码:
1、视图页面的JS:
$(function () { $('#file_upload').uploadify({ 'buttonText': '请选择上传文件', //设置上传按钮显示文字 'fileTypeExts': '*.doc;*.docx;*.xls;*.xlsx;*.ppt;*.htm;*.html;*.txt;*.zip;*.rar;*.gz;*.bz2;*.pdf;*.exe;*.jpg;*.bmp;*.jpeg;*.gif;*.png', //设置允许上传图片格式描述,即允许上传的文件类型。 'sizeLimit': '51200', // 设置上传大小,默认单位为KB。 //'queueSizeLimit': 1, //设置上传队列中同时允许的上传文件数量,默认为999 //'uploadLimit' : 1 //设置允许上传的文件数量,默认为999。 //单个文件上传完成时触发事件 //'onUploadComplete': function (file) { // alert('The file ' + file.name + ' finished processing.'); //}, //单个文件上传成功后触发事件。 //上传之前判断文件是否存在 'checkExisting': '/Sys/check_exists', 'onUploadSuccess': function (file, data, response) { eval("data=" + data); //alert('文件 ' + file.name + ' 已经上传成功,并返回 ' + response + ' 保存文件名称为 ' + data.SaveName); saveAttachment(file.name, data.SaveName) }, 'swf': '@Url.Content("~/Scripts/uploadify-v3.1/uploadify.swf")', 'uploader': '/Sys/UploadAtt_originalName' }); });
2、C#的check_exists action
[HttpPost] public ActionResult check_exists(string filename = null) { if (filename == null) { return Content("null"); } else { Int16 belongTo = 1; var attList = db_reqAtt.sys_reqAttachments.Where(a => a.belongTo == belongTo).Where(a => a.attachment == filename).AsQueryable(); if (attList.Count() > 0) { return Content("1"); } else { return Content("0"); } } }
3、jquery.uploadify.js关于onUploadStart有部分要修改的,修改如下:
onUploadStart : function(file) { // Load the swfupload settings var settings = this.settings; var timer = new Date(); this.timer = timer.getTime(); this.bytesLoaded = 0; if (this.queueData.uploadQueue.length == 0) { this.queueData.uploadSize = file.size; } if (settings.checkExisting) { $.ajax({ type : 'POST', async : false, url : settings.checkExisting, data : {filename: file.name}, success : function(data) { if(data == "null"){ alert("filename is null"); } else if (data == 1) { var overwrite = confirm('A file with the name "' + file.name + '" already exists on the server.\nWould you like to replace the existing file?'); if (!overwrite) { $('#file_upload').uploadify('cancel', file.id); //this.cancelUpload(file.id); $('#' + file.id).remove(); if (this.queueData.uploadQueue.length > 0 && this.queueData.queueLength > 0) { if (this.queueData.uploadQueue[0] == '*') { this.startUpload(); } else { this.startUpload(this.queueData.uploadQueue.shift()); } } } } } }); } // Call the user-defined event handler if (settings.onUploadStart) settings.onUploadStart.call(this, file); },
阅读全文
0 0
- C#应用 uploadify 上传前判断文件是否存在
- jQuery上传插件uploadify判断文件是否存在
- 判断上传前,判断本机文件(上传的文件)是否存在
- 上传文件时判断文件夹是否存在
- C# 判断 文件路径/文件 是否存在
- C#怎样判断文件是否存在和文件夹是否存在
- C#判断文件及文件夹是否存在
- C#判断文件是否存在方法
- C#判断远程文件是否存在
- C#判断某个文件是否存在
- c# 判断远程文件是否存在
- C# C++ 判断文件 文件夹是否存在
- C# 判断远程文件是否存在
- 判断应用是否存在
- C# 检查网络是否连通,判断远程文件是否存在
- 判断文件是否存在
- 判断文件是否存在
- 判断文件是否存在
- 手写python爬虫第二弹
- css3实现圆形进度加载动画
- MarkDownPad2简单使用
- Ubuntu14.04下tftp安装,并与开发板通信。
- Java引用类型
- C#应用 uploadify 上传前判断文件是否存在
- Struts2_生成验证码实例
- jQuery 判断 CheckBox是否被选中
- HDU 1171 Big Event in HDU (多重背包)
- Jboss SpringMVC调用WebService报错:setProperty must be overridden by all subclasses of SOAPMessage
- listview 修改当前item的子控件的属性
- 微信支付-商户后台(3)
- python:beautifulSoup学习(来自学习资料)
- 网页打开速度的心理学