参考的https://www.cnblogs.com/lvdabao/p/3452858.html这位,在此基础上略有修改:

1.根据Layer,将上传附件做成弹窗显示,引入frame弹窗,在项目当中能够通用

2.附件支持上移,下移排序功能

先贴出上传html页面,JS的代码

<script type="text/javascript">

        $(function () {
$('#upload').Huploadify({
auto: true,
fileTypeExts: '*.jpg;*.pdf;*.docx;*.doc;*.txt;*.ppt;*.pptx;*.gif;*.xls;*.rar;*.sql;*.ico;*.zip;*.csv;*.tiff;*.xlsx;*.mp3;*.mp4;*.vsdx;*.png',
multi: true,
formData: { key: 123456, key2: 'vvvv' },
fileSizeLimit: 99999999,//限制上传文件大小
showUploadedPercent: true,//是否实时显示上传的百分比,如20%
showUploadedSize: false,//是否实时显示已上传的文件大小,如1M/2M
removeTimeout: 9999999,
uploader: '../ashx/Upload.ashx',
onUploadStart: function (file) {
//console.log('开始上传');
},
onInit: function () {
//console.log('初始化');
InitUpload();
},
onUploadComplete: function () {
//console.log('上传完成');
},
onDelete: function (file) {
//console.log('删除的文件:' + file);
//console.log(file);
},
onUploadSuccess: function (file, data, response) {
var jsondata = eval('(' + data + ')');
if (jsondata.resultcode == "1000") {
$("#hid_filepath_" + file.index).val(jsondata.datas.FilePath);
$("#hid_filename_" + file.index).val(jsondata.datas.FileName);
$("#hid_filetitle_" + file.index).val(jsondata.datas.FileTitle);
//显示确定按钮
$("#upload_submit").show();
} else {
layer.msg(jsondata.errormsg);
$("#fileupload_1_" + file.index).remove();
}
},
onUploadError: function (file, errorCode, errorMsg, errorString) {
alert("上传出现错误,请联系管理员!");
$("#fileupload_1_" + file.index).remove();
console.log("失败:" + file.name + "_errorcode:" + errorCode + "_errorMsg:" + errorMsg + "_errorString:" + errorString);
}
}); //上移
$("#upload").on("click", ".up_btn", function () {
var now_id = $(this).parent().attr('id');
var up_id = $(this).parent().prev().attr('id');
if (up_id != null && up_id != "undefined") {
var nowhtml = $("#" + now_id).prop("outerHTML");
$("#" + up_id).before(nowhtml);
$(this).parent().remove();
} else {
alert("已经是第一个,无法上移!");
}
});
//下移
$("#upload").on("click", ".down_btn", function () {
var now_id = $(this).parent().attr('id');
var next_id = $(this).parent().next().attr('id');
if (next_id != null && next_id != "undefined") {
var nowhtml = $("#" + now_id).prop("outerHTML");
$("#" + next_id).after(nowhtml);
$(this).parent().remove();
} else {
alert("已经是最后一个,无法下移!");
}
});
//删除
$("#upload").on("click", ".delfilebtn", function () {
$(this).parent().remove();
if ($(".uploadify-queue-item").length <= 0) {
//隐藏确定按钮
$("#upload_submit").hide();
}
});
//确定
$("#upload_submit").click(function () {
var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
var filename_h = "";
var filepath_h = "";
var filetitle_h = "";
$(".hidden_name").each(function () {
filename_h += $(this).val() + ",";
});
$(".hidden_file").each(function () {
filepath_h += $(this).val() + ",";
});
$(".hidden_title").each(function () {
filetitle_h += $(this).val() + ",";
});
filename_h = filename_h.substr(0, filename_h.length - 1);
filepath_h = filepath_h.substr(0, filepath_h.length - 1);
filetitle_h = filetitle_h.substr(0, filetitle_h.length - 1);
var arr_a = filepath_h.split(',');
var arr_b = filename_h.split(',');
var arr_c = filetitle_h.split(',');
var strHtml = "";
for (var i = 0; i < arr_a.length; i++) {
var name = arr_b[i];
if (arr_b[i].length > 15) {
var name2 = arr_b[i].substr(arr_b[i].indexOf('.') - 3, arr_b[i].length);
var name1 = arr_b[i].substr(0, 7) + "......" + name2;
name = name1;
}
strHtml += "<a href='" + arr_a[i] + "' title='" + arr_c[i] + "' target='_blank'>" + name + ";</a>";
}
parent.$("#div_link").html(strHtml);
parent.$("#hidden_filepath").val(filepath_h);
parent.$("#hidden_filename").val(filename_h);
parent.layer.close(index);
});
}); //初始化
function InitUpload() {
//得到已上传文件html
var paths = parent.$("#hidden_filepath").val();
var names = parent.$("#hidden_filename").val();
var namesarray = names.split(',');
var index = 1;
parent.$("#div_link").find("a").each(function () {
var txt = $(this).text().substr(0, $(this).text().length - 1);
var path = $(this).attr("href");
var title = $(this).attr("title"); var divhtml = '';
divhtml += '<div id="fileupload_1_' + index + '" class="uploadify-queue-item"><div class="uploadify-progress">';
divhtml += '<div class="uploadify-progress-bar" style="width:100%;"></div></div>';
divhtml += '<span class="up_percent">100%</span><span class="delfilebtn">删除</span>';
divhtml += '<span id="upbtn_' + index + '" class="up_btn">上移</span><span id="downbtn_' + index + '" class="down_btn">下移</span>';
divhtml += '<span class="up_filename">' + txt + '</span>';
divhtml += '<input type="hidden" id="hid_filepath_' + index + '" class="hidden_file" value="' + path + '">';
divhtml += '<input type="hidden" id="hid_filename_' + index + '" class="hidden_name" value="' + namesarray[index - 1] + '">';
divhtml += '<input type="hidden" id="hid_filetitle_' + index + '" class="hidden_title" value="' + title + '"></div>';
$("#file_upload_1-queue").append(divhtml);
index += 1;
});
if (parent.$("#div_link").find("a").length > 0) {
//显示确定按钮
$("#upload_submit").show();
}
}
</script>

接下来是html代码:

<div id="upload_div">
<div id="upload"></div>
<div style="float: right;">
<input id="upload_submit" style="display: none;" type="button" value="确定" />
</div>
</div>

以下是调用附件页面HTML,隐藏的两个input是存储附件信息:

                                            <input id="layer_btn_upload" type="button" value="选择" />
<div id="div_link">
</div>
<input type="hidden" id="hidden_filepath" />
<input type="hidden" id="hidden_filename" />

然后是点击按钮上传附件事件:

            //弹窗上传附件
$("#layer_btn_upload").click(function () {
layerIndex = layer.open({
type: 2,
offset: '50px',//上 左,弹窗位置
shadeClose: true,
area: ['820px', '320px'],
title: "附件上传",
content: '../Upload.html'//链接页面
});
});

需要引用的JS和CSS

jquery.js//必须

layer.js//弹窗插件:http://layer.layui.com/

upload.html需要的CSS和JS

<link href="../assets/uploadify/Huploadify.css" rel="stylesheet" />
<script src="../assets/js/jquery.js"></script>
<script src="../assets/layer/layer.js"></script>
<script src="../assets/uploadify/jquery.Huploadify.js"></script>

页面效果:

Uploadify JS及CSS源码

Layer官网下载

文件过大有可能会报404错误解决方案:web.config

<system.web>
<httpRuntime executionTimeout="3600" maxRequestLength="204800" requestValidationMode="2.0" />
<system.web> <system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2097152000" maxQueryString="5000" maxUrl="8000"></requestLimits>
</requestFiltering>
</security>
</system.webServer>

  

asp.net 文件上传 Uploadify HTML5 带进度条的更多相关文章

  1. Ajax文件上传并添加Bootstrap进度条

    1.项目中需要用到文件上传和显示进度,网上各种插件搞得头晕,决定自己实现一个 三个步骤:Ajax上传文件,获取上传进度,显示进度 html: <!DOCTYPE HTML> <htm ...

  2. asp.net 文件上传示例整理

    ASP.NET依托.net framework类库,封装了大量的功能,使得上传文件非常简单,主要有以下三种基本方法. 方法一:用Web控件FileUpload,上传到网站根目录.  代码如下 复制代码 ...

  3. 文件上传~Uploadify上传控件~续(多文件上传)

    对于Uploadify文件上传之前已经讲过一次(文件上传~Uploadify上传控件),只不过没有涉及到多文件的上传,这回主要说一下多个文件的上传,首先,我们要清楚一个概念,多文件上传前端Upload ...

  4. IIS7.5修改asp的文件上传限制方法

    第一.IIS7.5修改asp的文件上传限制方法 1.打开IIS 2.打开面板中的应用程序开发 asp 3.找到最后的限制属性 4.修改其中的最大请求实体主体限制的值:默认为200000字节,等于195 ...

  5. asp.net文件上传进度条研究

    文章:asp.net 文件上传进度条实现代码

  6. Cookie操作、ASP.Net文件上传HttpPostedFile

    概述 Cookie用来保存客户浏览器请求服务器页面的请求信息. 我们可以存放非敏感的用户信息,保存时间可以根据需要设置.如果没有设置Cookie失效日期,它的生命周期保存到关闭浏览器为止,Cookie ...

  7. Android OkHttp文件上传与下载的进度监听扩展

    http://www.loongwind.com/archives/290.html 上一篇文章介绍了用Retrofit实现文件的上传与下载,但是我们发现没办法监听上传下载的进度,毕竟我们在做开发的时 ...

  8. js实现图片上传预览及进度条

    原文js实现图片上传预览及进度条 最近在做图片上传的时候,由于产品设计的比较fashion,上网找了比较久还没有现成的,因此自己做了一个,实现的功能如下: 1:去除浏览器<input type= ...

  9. 打造 html5 文件上传组件,实现进度显示及拖拽上传,支持秒传+分片上传+断点续传,兼容IE6+及其它标准浏览器

    老早就注册了博客园帐号,昨天才发现,连博客都没开,Github也是一样,深觉惭愧,赶紧潜个水压压惊`(*∩_∩*)′ 言归正传.大概许多人都会用到文件上传的功能,上传的库貌似也不少,比如(jQuery ...

随机推荐

  1. 解决vi编辑器不能使用方向键和退格键问题的两种方法

    方法1.使用vi命令时,不能正常编辑文件,使用方向键时老是出现很多字母? 在Ubuntu中,进入vi命令的编辑模式,发现按方向键不能移动光标,而是会输出ABCD,以及退格键也不能正常删除字符.这是由于 ...

  2. js随机产生区间数

    function selectFrom(startNumber, endNumber) { //1.从几开始 2.到几结束 var choice = endNumber - startNumber + ...

  3. day2 作业

    1.判断下列逻辑语句的True,False. 1),1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6     ...

  4. Java入门篇(五)——Java的字符串/String类

    前面在举例时有出现过String的例子,当时肯定有一部分朋友不知道这个是做什么用的.其实String类是Java中一个比较特殊的类,字符串即String类,它不是Java的基本数据类型之一,但可以像基 ...

  5. 自定义alert弹框

    /**************** UIAlertControllerStyleAlert *************************/ /*创建一个 可以自定义文字颜色和字体大小的IAler ...

  6. Codeforces 895C - Square Subsets 状压DP

    题意: 给了n个数,要求有几个子集使子集中元素的和为一个数的平方. 题解: 因为每个数都可以分解为质数的乘积,所有的数都小于70,所以在小于70的数中一共只有19个质数.可以使用状压DP,每一位上0表 ...

  7. Powerdesigner+Execel

    1.将Powerdesigner中的表(PDM)导入到execel中 Ctrl+Shift+X/tool->Execute commands ->Edit/Run script 粘贴如下v ...

  8. MYSQL Nested Join Optimization

    table_factor的语法和标准sql比较,后者只接受table_reference,每个逗号项都等于一个inner Join,e.g. SELECT * FROM t1 LEFT JOIN (t ...

  9. Java数据持久层框架 MyBatis之API学习六(Mapper XML 文件详解)

    对于MyBatis的学习而言,最好去MyBatis的官方文档:http://www.mybatis.org/mybatis-3/zh/index.html 对于语言的学习而言,马上上手去编程,多多练习 ...

  10. Linuxc - 通过管道,让小程序更有活力

    通过管道,让小程序更有活力 root@jiqing:~/cspace/les6# ls avg.c avg.out input.c input.out 一个负责输入,一个负责统计平均值 avg.c # ...