Uploadify使用随笔
最近项目使用了Uploadify一个上传插件,感觉的挺好用的。
上传控件:
引用JS
<script src='<% =ResolveUrl("~/JS/Uploadify/jquery.uploadify.js")%>' type="text/javascript"></script>
插件使用方法:
function UploadFY() {
var upload = {
'swf': '../JS/Uploadify/uploadify.swf',
'uploader': '../Ashx/FileOpHandler.ashx?Op=UploadFile&KGuid=' + Kguid + '&dType=SHPY_Files',
'buttonImg': '<% =ResolveUrl("~/JS/Uploadify/licon_001.gif")%>',
'cancelImg': '<% =ResolveUrl("~/JS/Uploadify/cancel.png")%>',
'queueID': Kguid,
'auto': true,
'multi': true,
'height': 22,
'width': 70,
'buttonText': '',
'fileTypeDesc': '系统支持文件', // The description for file types in the browse dialog
'fileTypeExts': '*.doc;*.docx;*.xls;*.xlsx;*.pdf;*.rar;*.gd',
//需要重写的事件
'overrideEvents': ['onSelectError', 'onDialogClose'],
'multi': false, //是否允许多选
'auto': true, //是否允许自动上传
'method': 'GET',
'queueSizeLimit': 300, //同时上传数量
'uploadLimit': 10000, //一次浏览器课上成总数量
'fileSizeLimit': '10MB', //单个文件大小设置
'sizeLimit': 4000000,
'onQueueComplete': function (file) { //所有文件上传完成时触发此事件
},
'onSelect': function (file) {
//$('#fileupload').uploadifySettings('formData', { 'ASPSESSID': ASPSESSID, 'AUTHID': auth });
//alert(formDate);
fileName = file.name;
},
//返回一个错误,选择文件的时候触发
'onSelectError': function (file, errorCode, errorMsg) {
switch (errorCode) {
case -100:
alert("上传的文件数量已经超出系统限制的" + $('#fileupload').uploadify('settings', 'queueSizeLimit') + "个文件!");
return;
case -110:
alert("文件 [" + file.name + "] 大小超出系统限制的10MB大小!");
// alert("文件 [" + file.name + "] 大小超出系统限制的" + $('#fileupload').uploadify('settings', 'fileSizeLimit') + "大小!");
return;
case -120:
alert("文件 [" + file.name + "] 大小超出系统限制的10MB大小!");
return;
case -130:
alert("文件 [" + file.name + "] 类型不正确!");
return;
default:
alert("文件 [" + file.name + "] 文件检查发生错误!");
return;
}
},
//检测FLASH失败调用
'onFallback': function () {
alert("您未安装FLASH控件,无法上传图片!请安装FLASH控件后再试。");
},
'width': 34, //文件选择按钮大小
'height': 22,
'removeCompleted': true,
'removeTimeout': 0.1, //上传完成后自动消失时间/秒
'onQueueComplete': function (file) { //所有文件上传完成时触发此事件
if (fileName.length > 100) {
alert("文件名过长!");
return;
}
$("#hdAttachmentName").val(fileName);
$("#hdAttachmentPath").val('/uploads/SHPY_Files' + '/' + Kguid + '/' + fileName);
$("#<%=DivFileLink.ClientID %>").html('<a href="javascript:void(0)" onclick="Down()" >' + fileName + '</a> <img src="../JS/Uploadify/cancel.png" align="middle" onclick=DeleteFile() />');
}
}
return upload;
}
function LoadUpload() {
$("input[type='file']").each(function () {
$(this).uploadify((UploadFY()))
});
}
function Down() {
document.getElementById('btnDown').click();
}
function DeleteFile() {
$("#hdAttachmentName").val('');
$("#hdAttachmentPath").val('');
$("#<%=DivFileLink.ClientID %>").html('');
//此处可写触发删除文件
}
页面加载的时候调用:
LoadUpload();
FileOpHandler.ashx
上传代码:
private void UploadFile(HttpContext context)
{
try
{
HttpPostedFile file = context.Request.Files["Filedata"];
string KGuid = q(context, "KGuid");
string FileName = file.FileName;
int FileLength = file.ContentLength; ;
string FileType = file.FileName.Substring(file.FileName.LastIndexOf("."));
string CreateUserName = q(context, "CreateUserName");
string CreateUserID = q(context, "CreateUserID");
DateTime CreateDateTime = DateTime.Now;
string uploadPath = context.Server.MapPath("..\\uploads\\" + q(context, "dType") + "\\" + KGuid + "\\");
string FilePath = "..\\uploads\\" + q(context, "dType") + "\\" + KGuid + "\\" + FileName;
if (file != null)
{
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
file.SaveAs(uploadPath + file.FileName);
//生成缩略图
}
context.Response.Write("1");
}
catch
{
context.Response.Write("0");
}
}
private string q(HttpContext context, string str)
{
if (context.Request[str] != null)
return context.Request[str].ToString();
return "";
}
public bool success
{
get;
set;
}
/// <summary>
/// Gets or sets the MSG.
/// </summary>
/// <value>The MSG.</value>
public string msg
{
get;
set;
}
/// <summary>
/// Gets or sets the public key.
/// </summary>
/// <value>The public key.</value>
public object data
{
get;
set;
}
文件下载:
protected void btnDown_Click(object sender, EventArgs e)
{
string filePath = Server.MapPath("../" + hdAttachmentPath.Value);
try
{
FileInfo info = new FileInfo(filePath);
if (!info.Exists)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "message", "$.messager.alert('消息提示', '文件不存在!', 'info');", true);
return;
}
long fileSize = info.Length;
Response.Clear();
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition", "attachment;filename=" +HttpUtility.UrlEncode( info.Name));
//不指明Content-Length用Flush的话不会显示下载进度
Response.AddHeader("Content-Length", fileSize.ToString());
Response.TransmitFile(filePath, 0, fileSize);
Response.Flush();
Response.Close();
}
catch (Exception ex)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "message", "$.messager.alert('消息提示', " + ex.Message + ", 'info');", true);
}
}
Uploadify使用随笔的更多相关文章
- 基于MVC4+EasyUI的Web开发框架形成之旅--附件上传组件uploadify的使用
大概一年前,我还在用Asp.NET开发一些行业管理系统的时候,就曾经使用这个组件作为文件的上传操作,在随笔<Web开发中的文件上传组件uploadify的使用>中可以看到,Asp.NET中 ...
- uploadify.js
基于uploadify.js实现多文件上传和上传进度条的显示 uploadify是JQuery的一个插件,主要实现文件的异步上传功能,可以自定义文件大小限制.文件类型.是否自动上传等属性,可以显示上传 ...
- 上传组件uploadify的使用
上传组件uploadify的使用 大概一年前,我还在用Asp.NET开发一些行业管理系统的时候,就曾经使用这个组件作为文件的上传操作,在随笔<Web开发中的文件上传组件uploadify的使用& ...
- 基于MVC4+EasyUI的Web开发框架形成之旅(4)--附件上传组件uploadify的使用
大概一年前,我还在用Asp.NET开发一些行业管理系统的时候,就曾经使用这个组件作为文件的上传操作,在随笔<Web开发中的文件上传组件uploadify的使用>中可以看到,Asp.NET中 ...
- asp.net(c#)开发中的文件上传组件uploadify的使用方法(带进度条)
上文件传很常见,现在就文件上传利用HTML的File控件(uploadify)的,这里为大家介绍一下(uploadify)的一些使用方法.在目前Web开发中用的比较多的,可能uploadify(参考h ...
- (转)基于MVC4+EasyUI的Web开发框架形成之旅--附件上传组件uploadify的使用
http://www.cnblogs.com/wuhuacong/p/3343967.html 大概一年前,我还在用Asp.NET开发一些行业管理系统的时候,就曾经使用这个组件作为文件的上传操作,在随 ...
- ASP.NET Uploadify 上传文件过大报错
Uploadify上传文件原来很早之前用过,没发现什么问题.今天再使用过程中,当文件大于30M的时候就会报错404.查看错误消息提示配置最大上传太小了.需要修改. 记得原来配置上传文件大小在这里:&l ...
- ASP.NET Uploadify 上传文件过大 报错(http error)借鉴,以防忘记
Uploadify上传文件原来很早之前用过,没发现什么问题.今天再使用过程中,当文件大于30M的时候就会报错404.查看错误消息提示配置最大上传太小了.需要修改. 记得原来配置上传文件大小在这里:&l ...
- jquery.uploadify文件上传组件
1.jquery.uploadify简介 在ASP.NET中上传的控件有很多,比如.NET自带的FileUpload,以及SWFUpload,Uploadify等等,尤其后面两个控件的用户体验比较好, ...
随机推荐
- spice命令使用
spicec.exe -h 192.168.1.1 -p 5912 -w 主机 物理机IP 端口号 主机
- Linux-ubuntu指令使用积累(长期更新)
alias cat cd cp ls mkdir mv rm sudo tar chmod 1. sudo 系统管理指令.放在其它指令之前使用,允许普通用户在root权限下执行部分或者全部 ...
- 关于java序列化中的一个细节
java序列化机制的可以参考很多资料了,最近在看的时候发现了一些问题. 1. 默认的序列化机制,很多书里讲到序列化类只序列化类名,实例变量,不会实例化类变量(static)和瞬态变量(transien ...
- 打开hibernate文件报警告
在web工程中新建一个,Hibetnate项目,打开配置文件报警高错误,This project is not a MyEclipse Hiberbate Project. Assuming Hibe ...
- ireport5.6+jasperreport6.3开发(二)--web开发的配置
ireport5.6只能编译出*.jasper的报表包,最终报表需要被输出为一个doc html pdf excel等文件,这时就需要jasperreport6.5的库进行配合了. jasperrep ...
- Laravel RuntimeException inEncrypter.php line 43: The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths
php artisan key:generate 运行上面代码即可解决
- Asp.net有关GridView的使用
一.带提示语句的删除 二.使用config里面的连接字符串 三.鼠标移到GridView某一行时改变该行的背景色方法 四.两个事件 五.GridView实现自动编号 不难写
- BurpSuite 抓手机包
Windows and Phone 处于同一无线环境下 Windows Phone Burp Suite设置
- OpenSUSE 开启SSH 和网络设置
一.开启SSH 1.确认SSH包已安装. 2.确认防火墙没有拦截. 3.确认SSH服务已启动.4.确认SSH配置文件设置正确. 环境: SSH已安装,防火墙设置不清楚,SSH服务已启动,配置文件不清楚 ...
- u盘文件恢复
同事的一个u盘,在别的机器上用过之后,插到自己的机器上,被360报警有木马,处理完后,一些文件和文件夹不见了. 拿到我的机器上,360弹出框问要不要处理,列表里显示有几个文件夹被隐藏起来了,选择显示后 ...