首先导入文件(官网上下载 kindeditor ):

<link href="~/kindeditor-4.1.11-zh-CN/kindeditor/themes/default/default.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.10.2.js"></script>
<script src="~/kindeditor-4.1.11-zh-CN/kindeditor/kindeditor-all.js"></script>
<script src="~/kindeditor-4.1.11-zh-CN/kindeditor/lang/zh-CN.js"></script>

前台代码:

<script language="javascript" type="text/javascript">
$(document).ready(function () {
KindEditor.ready(function (K) {
var editor = K.editor({
uploadJson: '/Upload/UploadImage?SaveUrl=3',
allowFileManager: true });
K('#btn_selectImage').click(function () {
editor.loadPlugin('multiimage', function () {
editor.plugin.multiImageDialog({
clickFn: function (urlList) {
var div = K('#div_imageView');
div.html('');
var arr = '';
K.each(urlList, function (i, data) {
arr = arr + data.url.substring(data.url.lastIndexOf("/") + ) + ",";
});
editor.hideDialog();
div.html("图片上传成功");
$("#imgmuttle").val(arr);//这里得到的是图片名字的一组数组。[1.jpg,2.jpg......]并存放到<input type="hidden" id="imgmuttle" />中 }
});
});
});
}); });
</script> <input type="button" id="btn_selectImage" value="批量上传">
<div id="div_imageView"></div>

后台接受图片方法:

   [HttpPost]
public ActionResult UploadImage(int SaveUrl)
{
//string kks = Request["category_id"];
string savePath = string.Empty;
string saveUrl = string.Empty; switch (SaveUrl)
{ case :
savePath = "/UpdateFiles/" + DateTime.Now.ToString("yyyy-MM-dd") + "/";
saveUrl = "/UpdateFiles/" + DateTime.Now.ToString("yyyy-MM-dd") + "/";
break;
default:
savePath = "/UpdateFiles/";
saveUrl = "/UpdateFiles/";
break;
} string fileTypes = "gif,jpg,jpeg,png,bmp";
int maxSize = ; Hashtable hash = new Hashtable(); HttpPostedFileBase file = Request.Files["imgFile"]; if (file == null)
{
hash = new Hashtable();
hash["error"] = ;
hash["url"] = "请选择文件";
return Json(hash);
} string dirPath = Server.MapPath(savePath);
if (!Directory.Exists(dirPath))
{
Directory.CreateDirectory(dirPath);
} string fileName = file.FileName;
string fileExt = Path.GetExtension(fileName).ToLower(); ArrayList fileTypeList = ArrayList.Adapter(fileTypes.Split(',')); if (file.InputStream == null || file.InputStream.Length > maxSize)
{
hash = new Hashtable();
hash["error"] = ;
hash["url"] = "上传文件大小超过限制";
return Json(hash);
} if (string.IsNullOrEmpty(fileExt) || Array.IndexOf(fileTypes.Split(','), fileExt.Substring().ToLower()) == -)
{
hash = new Hashtable();
hash["error"] = ;
hash["url"] = "上传文件扩展名是不允许的扩展名";
return Json(hash);
}
string fileUrl = "";
if (SaveUrl == )
{
string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + fileExt;
string filePath = dirPath + "tmep/" + newFileName;
file.SaveAs(filePath);
//fileUrl = saveUrl + Command.command.addWaterMark(filePath, fileExt, dirPath);
}
else
{
string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + fileExt;
string filePath = dirPath + newFileName;
file.SaveAs(filePath);
fileUrl = saveUrl + newFileName; }
hash = new Hashtable();
hash["error"] = ;
hash["url"] = fileUrl; return Json(hash, "text/html;charset=UTF-8"); ;
}

效果:

点击开始上传,上传完成后会显示原图

这是上传到项目里的图片文件夹:

Mvc 批量图片上传的更多相关文章

  1. jq实现批量图片上传

    http://blog.csdn.net/lmj623565791/article/details/31513065 jq实现批量图片上传 http://blog.csdn.net/lmj623565 ...

  2. android批量文件上传(android批量图片上传)

    项目中多处用到文件批量上传功能,今天正好解决了此问题,在此写出来,以便日后借鉴. 首先,以下架构下的批量文件上传可能会失败或者不会成功:   1.android客户端+springMVC服务端:服务端 ...

  3. 简单2步实现 asp.net mvc ckeditor 图片上传

    1.打开ckeditor 包下的  config.js,添加一句 配置(PS:ckeditor 很多功能都在该配置文件里配置),如下: config.filebrowserImageUploadUrl ...

  4. 无刷新的批量图片上传插件.NET版

    啥都不说,先上效果图: 这是一个网上的第三方组件,原版是php的,我用.NET重写了图片上传的处理,下面贴上代码 using System; using System.Collections.Gene ...

  5. Asp.net MVC 实现图片上传剪切

    使用技术:Asp.net MVC与jquery.uploadify,Jcrop 首先上页面 01 <strong><!DOCTYPE html> 02  <html> ...

  6. .net MVC 简单图片上传

    主要完成的是在网页上 上传一张图片到服务器 我搜出来的上传文件代码都特别复杂,对于初学者来说,先解决能上传的问题才最重要,并不需要特别多的功能,仅适合不会上传的初学者,大神请绕路,错误请指出,谢谢 v ...

  7. c# ASP.NET MVC easyui-filebox 图片上传和显示

    原文:https://www.cnblogs.com/huatao/p/4727398.html https://www.cnblogs.com/weiweithe/p/4363458.html 表单 ...

  8. MVC WebApi 图片上传和显示

    1 MVC中显示 内存流 中的图片.(不是图片文件) 创建一个Index用来显示 Action: public ActionResult Index() { return View(); } csht ...

  9. ___简单的MVC单个图片上传预览

    js: $("#btnImg").click(function () { $("#form0").ajaxSubmit({ url: "/Studen ...

随机推荐

  1. Spring 单例模式

    恶汉模式:Ehan.java package com.cn.danli; /** * 饿汉式单例模式 */ public class Ehan { private static Ehan eh = n ...

  2. HanLP用户自定义词典源码分析

    HanLP用户自定义词典源码分析 1. 官方文档及参考链接 关于词典问题Issue,首先参考:FAQ 自定义词典其实是基于规则的分词,它的用法参考这个issue 如果有些数量词.字母词需要分词,可参考 ...

  3. vue 移动端日期选择组件 vue-mobile-calendar

    vue-mobile-calendar cnpm install vue-mobile-calendar -S import Vue from 'vue' import Calendar from ' ...

  4. Android允许在UI线程中使用网络访问

    StrictMode.ThreadPolicy policy=new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode ...

  5. MobSF移动渗透测试框架

    1.https://github.com/MobSF/Mobile-Security-Framework-MobSF/wiki/1.-Documentation 2.http://www.freebu ...

  6. Learn jQuery in y seconds

    [兼容IE8以下没办法][虽不是Modern Web(不建议直接操作DOM)但也是一大利器] 个人推荐书[CSS 网站实录][JavaScript Dom 编程艺术][刚开始学不能太纠结机制机理原理因 ...

  7. steps/train_mono.sh

    <<单音素HMM的训练流程图.vsdx>> 定义拓扑结构.参数初始化 $ gmm-init-mono --shared-phones=$lang/phones/sets.int ...

  8. ORM映射和路由系统

    ORM映射: OBJECT ====> 对象 RELATION ===> 联系 MODEL ===> 数据模型 安装pyMysql 安装flask-sqlAchemy 导入: fro ...

  9. python加密(MD5)

    # import hashlib # # 1. 创建一个MD5对象 # obj = hashlib.md5(b"flkjsdalkfjklasdjfklasjkflasdjklfasdjfl ...

  10. 影子节点 shadowDOM

    示例: <video controls autoplay name="media"> <source id="mp4" src="t ...