初始上传界面

 //链接添加弹窗 html代码段↓
var msgcontent = "";
msgcontent += '<ul class="linkAddBox">';
msgcontent += '<li><p class="Z_pHOTOtIPS p10" style="margin-top:0;display: inline-block;"><b class="Z_TipsIcon fl mr5"></b><span class="fl mt4 color6">说明:一次可以最多可以上传50张.jpg .png .bmp .gif格式的图片,每张不超过10M。按<b>ctrl</b>或<b>shift</b>可选择多张</span></p></li>';
msgcontent += '<li><span> 选择专辑:</span><select class="typeselectdata"><option value="0">全部专辑</option></select></li>';
msgcontent += '<li class="clearfix">';
msgcontent += '<div id="ChoosePhoto"><img src="/Public/Image/Upload.jpg" style=" width: 80px;height: 40px;"/></div>';
msgcontent += '</li> <li><div id="fileList" class="uploader-list clearfix" style="max-height: 300px;overflow: auto;"></div></li></ul>';
//链接添加弹窗 html代码段↑
dia = $.dialog({
title: '添加专辑图片',
content: msgcontent,
fixed: true,
min: false,
max: false,
lock: true,
okVal: '确定',
ok: function() {
return s;//单击确定按钮时暂不关闭弹出框
},
cancelVal: '取消',
cancel: true
});
UploadImge();

控件初始化

//批量上传图片
function UploadImge() {
$list = $(window.parent.document).find('#fileList'),
// 优化retina, 在retina下这个值是2
ratio = window.devicePixelRatio || 1,
// 缩略图大小
thumbnailWidth = 100 * ratio,
thumbnailHeight = 100 * ratio,
// 初始化Web Uploader
uploader = WebUploader.create({
// 自动上传true/false。
auto: false,
// swf文件路径
swf: '/Portal/Js/Common/diyUpload/js/Uploader.swf',
// 内部根据当前运行是创建,可能是input元素,也可能是flash.
pick: $(window.parent.document).find("#ChoosePhoto"),
// 只允许选择文件,可选。
accept: {
title: 'Images',
extensions: 'gif,jpg,jpeg,bmp,png',
mimeTypes: 'image/gif,image/jpg,image/jpeg,image/bmp,image/png'
}
});
// 当有文件添加进来的时候
uploader.on('fileQueued', function(file) { var filetype = file.name.split('.')[1];
var st = false;
switch (filetype) {
case "gif":
st = true;
break;
case "jpg":
st = true;
break;
case "jpeg":
st = true;
break;
case "bmp":
st = true;
break;
case "png":
st = true;
break;
default:
break;
}
if (!st) {
jsprint('请上传正确格式的图片:"gif,jpg,jpeg,bmp,png"!!', '', 'Error');
return false;
}
$(window.parent.document).find(".ui_state_highlight").unbind("click").bind("click", function() {
Tid = $(window.parent.document).find(".typeselectdata option:selected").val();
if (Tid == 0) {
jsprint('专辑不能为空!!', '', 'Error');
return false;
}
var obj = {};
obj = { op: "uploadphoto", Tyid: Tid, navName: navName };
if (uploader.getFiles("inited").length > 0) {
uploader.option("formData", obj);
uploader.option("server", "/Ajax/Manage.ashx");
uploader.upload();
}
else {
jsprint('未选择任何视频文件!!', '', 'Error');
return false;
}
});
var $li = $(
'<div id="' + file.id + '" class="file-item thumbnail" style="float: left; margin-left: 5px;">' +
'<img>' +
'<div class="info">' + file.name + '</div>' +
'</div>'
),
$img = $li.find('img'); $list.append($li);
// 创建缩略图
uploader.makeThumb(file, function(error, src) {
if (error) {
$img.replaceWith('<span>不能预览</span>');
return;
} $img.attr('src', src);
}, thumbnailWidth, thumbnailHeight);
});
// 文件上传过程中创建进度条实时显示。
uploader.on('uploadProgress', function(file, percentage) {
var $li = $(window.parent.document).find('#' + file.id),
$percent = $li.find('.progress span');
// 避免重复创建
if (!$percent.length) {
$percent = $('<p class="progress"><span></span></p>')
.appendTo($li)
.find('span');
}
$percent.css('width', percentage * 100 + '%');
}); // 文件上传成功,给item添加成功class, 用样式标记上传成功。
uploader.on('uploadSuccess', function(file) {
$(window.parent.document).find('#' + file.id).addClass('upload-state-done');
});
// 文件上传失败,现实上传出错。
uploader.on('uploadError', function(file) {
var $li = $(window.parent.document).find('#' + file.id),
$error = $li.find('div.error');
// 避免重复创建
if (!$error.length) {
$error = $('<div class="error"></div>').appendTo($li);
}
$error.text('上传失败');
}); // 完成上传完了,成功或者失败,先删除进度条。
uploader.on('uploadComplete', function(file) {
$(window.parent.document).find('#' + file.id).find('.progress').remove();
if (uploader.getFiles().length == uploader.getStats().successNum) {//当上传成功后重新加载数据
dia.close();//上传完成时关闭弹出框
BindPhotoes(1, 20);//重新加载数据
}
});
}

一般处理程序处理上传图片

 HttpFileCollection fileCollection = cnt.Request.Files;//获取客户端传来的文件六流
if (fileCollection.Count == )
{
//未接收到文件
//防止发生异常
cnt.Response.Write(JsonHelper.SerializeObject(new { status = false, msg = "你未选中任何图片" }));
return;
}
System.Drawing.Image img = System.Drawing.Image.FromStream(fileCollection[].InputStream);
//服务器段相对路径,上传到相册所在的文件夹下
string relativePath = "/Upload/PhotoImage/" + usermodel.xj_UserName + "/" + DateTime.Now.ToString("yyyyMM");
strpath = UploadImg(fileCollection, relativePath);//获得文件存储路径
if (strpath == "")
{
cnt.Response.Write(JsonHelper.SerializeObject(new { status = false, msg = "保存图片发生异常" }));
return;
}

图片处理函数

  /// <summary>
/// 处理上传图片
/// </summary>
/// <param name="Id"></param>
/// <param name="Gid"></param>
/// <returns></returns>
private string UploadImg(HttpFileCollection fileCollection, string relativePath)
{
// 映射到服务器上的物理路径
string physicalPath = cnt.Server.MapPath(relativePath);
if (!Directory.Exists(physicalPath))
{
Directory.CreateDirectory(physicalPath);
}
//以当前时间为随机种子
Random rand = new Random( * (int)DateTime.Now.Ticks);
int fileId = rand.Next();
string ext = fileCollection[].FileName.Split('.').Last().ToLower();
string fileName = fileId + "." + ext;
//保存文件到本地
fileCollection[].SaveAs(physicalPath + fileName);
string filePath = relativePath + fileName;
return filePath;//返回缩略图和原图保存路径
}

依赖弹出框lhdaiglog的基于WebUploader批量上传图片的更多相关文章

  1. 弹出框一 之 基于bootstrap和jquery的自定义弹出框

    (function ($) { window.Ewin = function () { var html = '<div id="[Id]" class="moda ...

  2. 弹出框 popover.js

    弹出框 popover.js 为任意元素添加一小块浮层,就像 iPad 上一样,用于存放非主要信息. 弹出框的标题和内容的长度都是零的话将永远不会被显示出来. 插件依赖 弹出框依赖 工具提示插件 ,因 ...

  3. 自定义弹出框基于zepto 记得引入zepto

    html <!DOCTYPE html> <html> <meta charset="utf-8"> <title></tit ...

  4. 基于HTML5 Canvas 实现弹出框

    用户鼠标移入时,有弹出框出现,这样的需求很常见.这在处理HTML元素实现时简单,但是如果是对HTML5 Canvas 构成的图形进行处理,这种方法不再适用,因为Canvas使用的是另外一套机制,无论在 ...

  5. 小解系列-解决WebUploader在谷歌浏览器下弹出框打开慢,在Bootstrap模态框内部多次点击才能触发的问题

    WebUploader百度前端团队开源的上传组件,用起来感觉真心不错的,标题的两个问题是我实际使用过程中遇到的问题,经过百度和谷歌查到解决方案, 特分享一下,以供遇到此问题的童靴. 谷歌浏览器弹出框打 ...

  6. .NET MVC 学习笔记(四)— 基于Bootstarp自定义弹出框

    .NET MVC 学习笔记(四)—— 基于Bootstarp自定义弹出框 转载自:https://www.cnblogs.com/nele/p/5327380.html (function ($) { ...

  7. 基于js alert confirm样式弹出框

    基于js alert confirm样式弹出框.这是一款根据alert confirm优化样式的确认对话框代码. 在线预览   源码下载 实现的代码. html代码: <div id=" ...

  8. 基于Vue.js PC桌面端弹出框组件|vue自定义弹层组件|vue模态框

    vue.js构建的轻量级PC网页端交互式弹层组件VLayer. 前段时间有分享过一个vue移动端弹窗组件,今天给大家分享一个最近开发的vue pc端弹出层组件. VLayer 一款集Alert.Dia ...

  9. 基于Selenium2+Java的UI自动化(6)-操作Alert、confirm、prompt弹出框

    alert.confirm.prompt这样的js对话框在selenium1 时代处理起来比价麻烦,常常要用autoit来帮助处理.而现在webdriver对这些弹出框做了专门的处理,使用seleni ...

随机推荐

  1. 24.Firewalld防火墙

    1.Firewalld防火墙的概述 RHEL/CentOS 7系统中集成了多款防火墙管理工具,其中firewalld是默认的防火墙配置管理工具它拥有基于CLI(命令行界面)和基于GUI(图形用户界面) ...

  2. JS基础语法---总结

    JS是一门什么样的语言? 是一门解释性的语言 是一门脚本语言 是一门弱类型语言,声明变量都用var 是一门基于对象的语言 是一门动态类型的语言:            1. 代码(变量)只有执行到这个 ...

  3. Linux shell--基础指令

    Linux shell--基础指令 浏览Linux文件系统 Linux中最基础也是最必要的一条指令 cd destination cd命令可接受单个参数destination,用以指定想切换到的目录名 ...

  4. 微信小程序开发——上传代码片段到git仓库

    微信开发者工具除了自带的git版本管理(本地服务)之外,还可以推送到在线git仓库中去,这样别人也可以通过git来拉取你的代码片段或小程序. 一.1.登录git 一.2.点击创建项目  一.3.填写项 ...

  5. bay——安装_Oracle 12C-单实例-Centos7.txt

    安装Oracle12C 总结笔记 IP:10.20.4.214 ---------------------------------------------用户和密码: root/bayaimbayai ...

  6. How to recover a skipped tablespace after an incomplete recovery? (Doc ID 1561645.1)

    How to recover a skipped tablespace after an incomplete recovery? (Doc ID 1561645.1) APPLIES TO: Ora ...

  7. Python-判断回文

    # 回文单词是从左到右和从右到左读相同的单词. # 例如:"detartrated"和"evitative"是回文 str_in = input('Input: ...

  8. Scrapy中的Request和日志分析

    Scrapy.http.Request 自动去重,根据url的哈希值,进行去重 属性 meta(dict)  在不同的请求之间传递数据,dict priority(int)  此请求的优先级(默认为0 ...

  9. 201871010106-丁宣元 《面向对象程序设计(java)》第一周学习总结

    丁宣元 <面向对象程序设计(java)>第一周学习总结 正文开头 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在 ...

  10. dfs的几个基础示例 acwin 91~94

    从 ~n 这 n 个整数中随机选取任意多个,输出所有可能的选择方案. 输入格式 输入一个整数n. 输出格式 每行输出一种方案. 同一行内的数必须升序排列,相邻两个数用恰好1个空格隔开. 对于没有选任何 ...