Uploadify v3.2.1

首先引用下面的文件

<!--上传控件 uploadify-->
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<link href="~/uploadify/uploadify.css" rel="stylesheet" />
<script src="~/uploadify/jquery.uploadify.js"></script>
                              <div class="col-md-10">
<p>
<!--记录地址-->
<input type="text" name="UR_Icon" id="UR_Icon" class="form-control" value="@Model.xxxx" />
</p>
<!--显示缩略图-->
<img id="showImage" />
<!--uploadify插件-->
<input type="file" name="file_upload" id="uploadify" />
<p>
<button type="button" class="btn btn-default" id="upload">上传</button>
<button type="button" class="btn btn-default" id="cancel">取消上传</button>
</p>
</div>
<script type="text/javascript">
$('#uploadify').uploadify({
uploader: '/FileUpLoad/UpLoadProcess', // 服务器端处理地址
swf: '/uploadify/uploadify.swf', // 上传使用的 Flash width: 90, // 按钮的宽度
height: 33, // 按钮的高度
buttonText: "选择图片", // 按钮上的文字
buttonCursor: 'hand', // 按钮的鼠标图标 fileObjName: 'Filedata', // 上传参数名称 // 两个配套使用
fileTypeExts: "*.jpg;*.png;*.gif", // 扩展名
fileTypeDesc: "请选择 jpg png gif 文件", // 文件说明 auto: false, // 选择之后,自动开始上传
multi: false, // 是否支持同时上传多个文件
queueSizeLimit: 1, // 允许多文件上传的时候,同时上传文件的个数 'itemTemplate': '<div id="${fileID}" class="uploadify-queue-item">\
<div class="cancel">\
<a href="javascript:$(\'#${instanceID}\').uploadify(\'cancel\', \'${fileID}\')">X</a>\
</div>\
<span class="fileName">${fileName} (${fileSize})</span><span class="data"></span>\<div class="uploadify-progress"><div class="uploadify-progress-bar"><!--Progress Bar--></div></div>\
</div>',
//从服务器端脚本返回数据
'onUploadSuccess': function (file, data, response) {
//设置缩略图的宽高
$('#showImage').attr('src', data).attr('style', 'width:90px;height:90px');
//给【input】 UR_Icon 控件赋值
$('#UR_Icon').val(data);
//alert('id: ' + file.id
// + ' - 索引: ' + file.index
// + ' - 文件名: ' + file.name
// + ' - 文件大小: ' + file.size
// + ' - 类型: ' + file.type
// + ' - 创建日期: ' + file.creationdate
// + ' - 修改日期: ' + file.modificationdate
// + ' - 文件状态: ' + file.filestatus
// + ' - 服务器端消息: ' + data
// + ' - 是否上传成功: ' + response); }
}); //上传开始
$('#upload').on('click', function () {
$('#uploadify').uploadify('upload', '*')
})
//取消上传
$('#cancel').on('click', function () {
$('#uploadify').uploadify('cancel', '*')
}) </script>

服务器

public ActionResult UpLoadProcess(HttpPostedFileBase Filedata)
{
string now = DateTime.Now.ToString("yyyy-MM-dd");
string upLoad = "UpLoad"; // 如果没有上传文件
if (Filedata == null ||
string.IsNullOrEmpty(Filedata.FileName) ||
Filedata.ContentLength == )
{
return this.HttpNotFound();
} //获取文件的保存路径
string uploadPath = Server.MapPath("\\" + upLoad + "\\" + now);
//判断上传的文件是否为空
if (Filedata != null)
{
//如果没有UpLoad这个文件夹
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
} } // 保存到 ~/UpLoad 文件夹中,名称不变
string filename = Guid.NewGuid().ToString("N") + Path.GetExtension(Filedata.FileName);
string virtualPath =
string.Format("/" + upLoad + "/{0}/{1}", now, filename);
// 文件系统不能使用虚拟路径
string path = this.Server.MapPath(virtualPath); Filedata.SaveAs(path); //返回虚拟路径
return Content(virtualPath);
}

不同地方,视图要修改的参数。

问题集锦:

1.先点击【修改窗口】,选择文件,但是没有传就关闭 modal 了。再在【添加】按钮里面,这个进度条还在?

顺带把img的地址清楚掉。

2.添加按钮和修改按钮的逻辑问题,自己看注释

//添加
$('#mytool').on('click', 'button#addModel', function () { //加载页面基本信息
$.ajax({
url: "/AdminUser/AdminUserForm",
type: "post",
//参数:(html5:MenuForm页面html数据)
success: function (html5) {
//只有在没赋值的情况下,才创建
if ($("#createModal").html() == "") { $("#createModal").html(html5); //弹出框show
$("#myModal").modal("show");
} else {
//点“添加”,清除掉进度条
$('#uploadify-queue').html(''); //重置添加 modal 里面的 input 的值为 null
$("#formMenu input[type='text']").val('');
//让select 选择 +<option selected="selected" value="-1">请选择一项数据!</option>
$("#formMenu select").val('-1');
}
//重置添加 modal 里面的 img 的值为 默认图片
$('#showImage').attr('src', 'UpLoad/image.png').attr('style', 'width:200px;height:150px');
}
});
}) /**
* 编辑
*/
$('#dataTables-example tbody').on('click', 'button#editrow', function () {
//当前行数据
var rows = tables.row($(this).parents('tr')).data();
//加载页面基本信息
$.ajax({
url: "/AdminUser/AdminUserForm",
type: "post",
data: rows,
success: function (data) {
var exp = rows.UR_Icon; //只有在没赋值的情况下,才创建
$("#createModal").html(data);
//缩略图赋值
$('#showImage').attr('src', $('#UR_Icon').val()).attr('style', 'width:200px;height:150px');
//弹出框show
$("#myModal").modal("show"); //必须先赋值,才能修改缩略图
if (exp == null || typeof (exp) == "undefined" || exp == ) {
//重置添加 modal 里面的 img 的值为 null(去掉图片缩略图)
$('#showImage').attr('src', 'UpLoad/image.png');
}
}
}); });

3.uploadify “ID SWFUpload_0 is already in use. The Flash Object could not be added”错误的解决方法

在使用 uploadify时 遇到同时加载的多个页面中包含uploadify组件时就会出现“ID SWFUpload_0 is already in use. The Flash Object could not be added”的错误,分析代码就会发现,时因为名字累加的问题,解决方法如下,

找到this.movieName,第72行 (jquery.uploadify.js)
 
this.movieName = "SWFUpload_" + SWFUpload.movieCount++;   //不能有效累加导致出现重名现象 
 
修改为随机   this.movieName = "SWFUpload_" + 

parseInt(100*Math.random());

注意:同时,<input type="file" name="file_upload" id="uploadify001" />

命名不能相同,这个要注意

4.“编辑”按钮,加载不出图片

解决方案:

参考:

http://www.cnblogs.com/haogj/archive/2013/04/27/3046138.html

http://www.cnblogs.com/mofish/archive/2012/11/30/2796698.html

http://www.buyuer.com/javaScript/61.html   SWFUpload_0 is already in use. The Flash Object could not be added

jquery文件上传控件 Uploadify 问题记录的更多相关文章

  1. jquery文件上传控件 Uploadify

    (转自 http://www.cnblogs.com/mofish/archive/2012/11/30/2796698.html) 基于jquery的文件上传控件,支持ajax无刷新上传,多个文件同 ...

  2. jquery文件上传控件 Uploadify 可以和ajax交互

    http://www.cnblogs.com/mofish/archive/2012/11/30/2796698.html  原网址 基于jquery的文件上传控件,支持ajax无刷新上传,多个文件同 ...

  3. jquery文件上传控件 Uploadify(转)

    原文:http://www.cnblogs.com/mofish/archive/2012/11/30/2796698.html 基于jquery的文件上传控件,支持ajax无刷新上传,多个文件同时上 ...

  4. jquery文件上传控件 WebUploader

    WebUploader是百度开源的一个文件上传组件,因为其操作简洁大方,就在项目中使用了,记录一下. 效果是这样子:  这个样子是默认的效果.  这个是选择上传的图片,可以批量,选择后可以删除和添加更 ...

  5. 使用Uploadify(UploadiFive)多文件上传控件遇到的坑

    最近项目中需要实现多文件上传功能,于是结合需求最终选择了Uploadify这一款控件来实现.相比其他控件,Uploadify具有简洁的界面,功能API基本可以解决大多数需求,又是基于jquery的,配 ...

  6. ***文件上传控件bootstrap-fileinput的使用和参数配置说明

    特别注意:    引入所需文件后页面刷新查看样式奇怪,浏览器提示错误等,可能是因为js.css文件的引用顺序问题,zh.js需要在fileinput.js后面引入.bootstrap最好在filein ...

  7. 在WebBrowser中通过模拟键盘鼠标操控网页中的文件上传控件(转)

    引言 这两天沉迷了Google SketchUp,刚刚玩够,一时兴起,研究了一下WebBrowser. 我在<WebBrowser控件使用技巧分享>一文中曾谈到过“我现在可以通过WebBr ...

  8. 因用了NeatUpload大文件上传控件而导致Nonfile portion > 4194304 bytes错误的解决方法

    今天遇到一个问题,就是“NeatUpload大文件上传控件而导致Nonfile portion > 4194304 bytes错误”,百度后发现了一个解决方法,跟大家分享下: NeatUploa ...

  9. 对FileUpload文件上传控件的一些使用方法说明

    //创建时间:2014-03-12 //创建人:幽林孤狼 //说明:FileUpload文件上传控件使用说明(只是部分)已共享学习为主 //可以上传图片,txt文档.doc,wps,还有音频文件,视屏 ...

随机推荐

  1. 如何优雅地使用 Sublime Text

    Sublime Text:一款具有代码高亮.语法提示.自动完成且反应快速的编辑器软件,不仅具有华丽的界面,还支持插件扩展机制,用她来写代码,绝对是一种享受.相比 于难于上手的Vim,浮肿沉重的Ecli ...

  2. IE盒模型

    IE5.5及更早的版本使用的是IE盒模型,在在IE6及以上版本的浏览器中,浏览器支持一种解决了这种差异的可选的渲染模式,也开始遵循标准模式. IE盒模型和W3C盒模型的差异: IE盒模型,块元素的实际 ...

  3. dp重拾-01背包--HDU 2602

    Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like ...

  4. PingUtil in Android

    Ping a host in Android:“ping -c 1 127.0.0.1”-c 1: The ping times. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 ...

  5. 网络数据包发送工具PacketSender中文源码

    在网上发现了一个好用的工具PacketSender,数据包发送器.对于写网络程序来说,有很大的便利性.虽然在linux下,netcat工具也很好用,但是这个也不错. 原本是英文的,给翻译了一下.这是基 ...

  6. python——tuple元组

    >>> dir(tuple) ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', ...

  7. A Font Lover

    Monaco / Consolas 有名的等宽字体. 效果不错. Linux Libertine 非常好的衬线字体. Liberation Serif 比较好. Gentium 非常好的衬线字体. B ...

  8. 教程和工具--用wxPython编写GUI程序的

    wxPython是个很好的GUI库,对底层的C++库进行了封装,调用起来很方便,尤其是操作前台UI界面和后台多线程,两者配合很方便,做GUI程序最难是写界面尤其是布局. 关于wxPython,自己正在 ...

  9. Access an instance through a console

    VNC or SPICE is used to view the console output of an instance, regardless of whether or not the con ...

  10. 注册页面的js验证

    简单的用户注册页面:(html) 包含用户名格式验证.邮箱格式验证.确认密码一致性验证和必填项验证.(纯javascript) <center> <h1>用户注册</h1 ...