ASP.NET MVC 4 中Jquery上传插件Uploadify简单使用-版本:3.2.1
1.官网下载开发包:http://www.uploadify.com/download/,选择免费的Flash版本:

2.解压后,需要用到以下几个文件:

需要修改uploadify.css中取消上传按钮的背景图片路径:
.uploadify-queue-item .cancel a {
background: url('../img/uploadify-cancel.png') 0 0 no-repeat;
float: right;
height: 16px;
text-indent: -9999px;
width: 16px;
}
3.页面添加样式表和脚本库的引用:
<link href="~/Content/uploadify/uploadify.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Content/uploadify/jquery.uploadify.min.js"></script>
4.页面添加用于生成上传按钮的标签:
<span id="btn_upload"></span>
5.初始化,生成按钮:
$(function () {
$('#btn_upload').uploadify({
uploader: '/article/upload', // 服务器处理地址
swf: '/Content/uploadify/uploadify.swf',
buttonText: "选择文件", //按钮文字
height: 34, //按钮高度
width: 82, //按钮宽度
fileTypeExts: "*.jpg;*.png;", //允许的文件类型
fileTypeDesc: "请选择图片文件", //文件说明
formData: { "imgType": "normal" }, //提交给服务器端的参数
onUploadSuccess: function (file, data, response) { //一个文件上传成功后的响应事件处理
var data = $.parseJSON(data);
alert(data.imgpath);
}
});
});
6.后台代码:
public ActionResult Upload(HttpPostedFileBase Filedata)
{
// 没有文件上传,直接返回
if (Filedata == null || string.IsNullOrEmpty(Filedata.FileName) || Filedata.ContentLength == )
{
return HttpNotFound();
} //获取文件完整文件名(包含绝对路径)
//文件存放路径格式:/files/upload/{日期}/{md5}.{后缀名}
//例如:/files/upload/20130913/43CA215D947F8C1F1DDFCED383C4D706.jpg
string fileMD5 = CommonFuncs.GetStreamMD5(Filedata.InputStream);
string FileEextension = Path.GetExtension(Filedata.FileName);
string uploadDate = DateTime.Now.ToString("yyyyMMdd"); string imgType = Request["imgType"];
string virtualPath = "/";
if (imgType == "normal")
{
virtualPath = string.Format("~/files/upload/{0}/{1}{2}", uploadDate, fileMD5, FileEextension);
}
else
{
virtualPath = string.Format("~/files/upload2/{0}/{1}{2}", uploadDate, fileMD5, FileEextension);
}
string fullFileName = this.Server.MapPath(virtualPath); //创建文件夹,保存文件
string path = Path.GetDirectoryName(fullFileName);
Directory.CreateDirectory(path);
if (!System.IO.File.Exists(fullFileName))
{
Filedata.SaveAs(fullFileName);
} var data = new { imgtype = imgType, imgpath = virtualPath.Remove(, ) };
return Json(data, JsonRequestBehavior.AllowGet);
}
}
7.相关参数说明:
- uploader: '/article/upload' 请求地址,对应于后台进行处理的Action;
- formData:{ "imgType":"normal" } 参数可以动态设置,一般在onUploadStart事件中进行处理:
onUploadStart:function(file){
$("#btn_upload").uploadify("settings", "formData", { "imgType": "other","imgMode":"big") });
}如果参数名与初始化的formData中一样,参数值将覆盖,否则添加。动态设置的方法在开始上传之前执行都是可以的,该试例在两个checkbox(通过bootstrap-switch美化)的状态切换时进行设置:
$('#img_mode').on('switch-change', function (e, data) {
$("#btn_upload").uploadify("settings", "formData", { "imgMode": (data.value ? "small" : "big") });
});
$('#img_type').on('switch-change', function (e, data) {
$("#btn_upload").uploadify("settings", "formData", { "imgType": (data.value ? "normal" : "big") });
}); - onUploadSuccess事件处理函数的3个参数:file、data、response
- file - 包含原始文件的信息;
- response - 后台返回true或false;
- data - 后台返回的数据,试例中为Json对象;
- 其他详细参数,参考官方文档:http://www.uploadify.com/documentation/
8.效果演示:


ASP.NET MVC 4 中Jquery上传插件Uploadify简单使用-版本:3.2.1的更多相关文章
- 【转】JQuery上传插件Uploadify使用详解及错误处理
转自:http://www.jb51.net/article/43498.htm 关于JQuery上传插件Uploadify使用详解网上一大把,基本上内容都一样.我根据网上的步骤配置完成后,会报一些错 ...
- JQuery上传插件uploadify优化
旧版的uploadify是基于flash上传的,但是总有那么些问题,让我们用的不是很舒服.今天主要分享下在项目中用uploadify遇到的一些问题,以及优化处理 官方下载 官方文档 官方演示 下面是官 ...
- jquery上传插件uploadify 报错http error 302 解决方法之一
前段时间用到jquery上传插件uploadify时,始终出现系统报出 http error 302 的错误. 网上大量搜集信息,基本上都是说session值丢失的问题,根据网友提供的解决方案进行修改 ...
- JQuery上传插件Uploadify使用详解 asp.net版
先来一个实例 Uploadify插件是JQuery的一个文件支持多文件上传的上传插件,ajax异步上传,实现的效果非常不错,带进度显示.不过官方提供的实例时php版本的,本文将详细介绍Uploadif ...
- JQuery上传插件Uploadify使用详解
本文转载http://www.cnblogs.com/oec2003/archive/2010/01/06/1640027.html Uploadify是JQuery的一个上传插件,实现的效果非常不错 ...
- (转)JQuery上传插件Uploadify使用详解
原文地址:http://www.cnblogs.com/oec2003/archive/2010/01/06/1640027.html Uploadify是JQuery的一个上传插件,实现的效果非常不 ...
- jQuery上传插件Uploadify使用帮助
Uploadify是JQuery的一个上传插件,实现的效果非常不错,带进度显示.它的功能特色总结如下: 支持单文件或多文件上传,可控制并发上传的文件数 在服务器端支持各种语言与之配合使用,诸如PHP, ...
- 文件上传利器JQuery上传插件Uploadify
在做日常项目中,经常在后台需要上传图片等资源文件,之前使用过几次这个组件,感觉非常好用 ,但是每次使用的时候都是需要经过一番查阅,所以还不如记住在这里,以后使用的时候就翻翻. 他的官方网站如下:htt ...
- JQuery上传插件Uploadify API详解
一.相关key值介绍uploader:uploadify.swf文件的相对路径,该swf文件是一个带有文字BROWSE的按钮,点击后淡出打开文件对话框,默认值:uploadify.swf. scrip ...
随机推荐
- for...else循环
如果for循环完整结束,无break打断循环,那么执行else里面的内容,否则不执行. while True: n = raw_input('>') for x in n: if x == 'f ...
- Android 开源项目PhotoView源码分析
https://github.com/chrisbanes/PhotoView/tree/master/library 这个就是项目地址,相信很多人都用过,我依然不去讲怎么使用.只讲他的原理和具体实现 ...
- 如何定义java中的类
3步走,如下示例代码所示: package com.imooc; //1.定义一个类 public class Telphone { //2.属性(成员变量)有什么 float screen; flo ...
- Windows下PHP+Eclipse开发环境搭建 及错误解决(apache2.2服务无法启动 发生服务特定错误:1)
前言 Eclipse与php/apache的关系:Eclipse只是用来写代码的,如果想要在浏览器查看运行效果就要让php/apache的运行目录指向你的代码目录.Eclipse貌似不会自己和apac ...
- JSON和JSONP有哪些区别,PhoneGap跨域请求如何实现
前言 由于Sencha Touch 2这种开发模式的特性,基本决定了它原生的数据交互行为几乎只能通过AJAX来实现. 当然了,通过调用强大的PhoneGap插件然后打包,你可以实现100%的Socke ...
- hibernate建表一对多 一的一方控制多的方
级联操作,操作class对象的时候 级联操作 student Classes.java文件 package cn.itcast.hiberate.sh.domain; import java.util ...
- 浏览器的DNS缓存
通过设置hosts文件可以强制指定域名对应的IP,当修改hosts文件,想要浏览器生效,最直接的方法关闭浏览器后重新开启:如果不想重启浏览器,只需要清空浏览器的DNS缓存即可.清空DNS缓存在chro ...
- js遇到这样基础题,看你能不能作对呢
var a = (function() { return typeof arguments; })(); alert(a); //Object var b = (function(x) { delet ...
- delphi 中怎么知道某一个月有多少天
if (month in (1,3,5,7,8,10,12)) return 31; else if (month in(4,6,9,11)) return 30; else if (year 是闰年 ...
- jquery ajax跨域的完美解决方法(jsonp方式)
ajax跨域请求的问题,JQuery对于Ajax的跨域请求有两类解决方案,不过都是只支持get方式,接下来为大家详细介绍下客户端JQuery.ajax的调用代码 今天在项目中需要做远程数据加载 ...