在线HTML文档编辑器使用入门之图片上传与图片管理的实现
在线HTML文档编辑器使用入门之图片上传与图片管理的实现:
官方网址: http://kindeditor.net/demo.php
开发步骤:
1.开发中只需要导入选中的文件(通常在 webapp 下,建立 editor 文件夹 )
导入:lang、plugins、themes、kindeditor.js/kindeditor-min.js-->放在editor文件夹下
2.在页面上引入相关的js&css文件
<!-- 导入Kindeditor相关文件 -->
<script type="text/javascript" src="../../editor/lang/zh_CN.js"></script>
<script type="text/javascript" src="../../editor/kindeditor.js"></script>
<link rel="stylesheet" href="../../editor/themes/default/default.css" />
3.在页面提供标签<textarea id="ta" name="ta"></textarea>
KindEditor.ready(function(K) {
window.editor = K.create("#ta");
4.定制工具栏按钮显示:
KindEditor.ready(function(K) {
window.editor = K.create("#ta", {
items: ['source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
'anchor', 'link', 'unlink', '|', 'about'
],allowFileManager:true,
uploadJson:"../../image_upload.action",
fileManagerJson:"../../image_manager.action"
});
5.上传图片与图片管理功能实现:
页面提供对应方法:
allowFileManager、uploadJson、fileManagerJson-->发送请求到后台action处理:
//提供属性注入
private File imgFile;
private String imgFileFileName;
private String imgFileContentType;
//图片上传方法
@Action(value = "image_upload", results = { @Result(name = "success", type = "json") })
public String uploadImg() throws IOException {
System.out.println("file:" + imgFile);
System.out.println("文件名称:" + imgFileFileName);
System.out.println("文件类型:" + imgFileContentType);
String savePath = ServletActionContext.getServletContext().getRealPath(
"/upload/");
String saveUrl = ServletActionContext.getRequest().getContextPath()
+ savePath;
// 生成随即图片名称
UUID randomUUID = UUID.randomUUID();
String ext = imgFileFileName
.substring(imgFileFileName.lastIndexOf("."));
String randomUrl = randomUUID + ext;
// 保存图片(绝对的路径和)
FileUtils.copyFile(imgFile, new File(savePath + "/" + randomUrl));
// 返回浏览器数据(文件上传成功了还是失败了)
Map<String, Object> map = new HashMap<String, Object>();
map.put("error", 0);
map.put("url", saveUrl + randomUrl);
ServletActionContext.getContext().getValueStack().push(map);
return SUCCESS;
} //图片管理方法
@Action(value = "image_manager", results = { @Result(name = "success", type = "json") })
public String manager() {
// 根目录路径(绝对路径)
String rootPath = ServletActionContext.getServletContext().getRealPath(
"/")
+ "upload/";
// 根目录URL(绝对路径)
String rootUrl = ServletActionContext.getRequest().getContextPath()
+ "/upload/";
List<Map<String, Object>> fileList = new ArrayList<Map<String, Object>>();
// 当前上传目录
File currentPathFile = new File(rootPath);
// 图片的扩展名
String[] fileTypes = new String[] { "gif", "jpg", "jpeg", "png", "bmp" }; if (currentPathFile.listFiles() != null) {
// 遍历目录取的文件信息
for (File file : currentPathFile.listFiles()) {
Map<String, Object> hash = new HashMap<String, Object>();
String fileName = file.getName();
if (file.isDirectory()) {
hash.put("is_dir", true);
hash.put("has_file", (file.listFiles() != null));
hash.put("filesize", 0L);
hash.put("is_photo", false);
hash.put("filetype", "");
} else if (file.isFile()) {
String fileExt = fileName.substring(
fileName.lastIndexOf(".") + 1).toLowerCase();
hash.put("is_dir", false);
hash.put("has_file", false);
hash.put("filesize", file.length());
hash.put("is_photo", Arrays.<String> asList(fileTypes)
.contains(fileExt));
hash.put("filetype", fileExt);
}
hash.put("filename", fileName);
hash.put("datetime",
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(file
.lastModified()));
fileList.add(hash);
}
}
Map<String, Object> result = new HashMap<String, Object>();
result.put("moveup_dir_path", "");
result.put("current_dir_path", rootPath);
result.put("current_url", rootUrl);
result.put("total_count", fileList.size());
result.put("file_list", fileList);
ActionContext.getContext().getValueStack().push(result);
return SUCCESS;
}
在线HTML文档编辑器使用入门之图片上传与图片管理的实现的更多相关文章
- 推荐ajaxfilemanager for tiny_mce 比较完善的tiny_mce编辑器的图片上传及图片管理插件PHP版 支持中文
tiny_mce编辑器,我觉得挺简洁.好用的,但就是图片上传的插件是收费的,而且网上找了半天也没有找到开源好用的上传插件. 不过功夫不负有心人,终于还就被我找到一款相当满意的插件. 这个插件的名字叫a ...
- swagger在线api文档搭建指南,用于线上合适么?
在上一篇文章中,我们讲解了什么是 api,什么是 sdk: https://www.cnblogs.com/tanshaoshenghao/p/16217608.html 今天将来到我们万丈高楼平地起 ...
- 解决SharePoint 文档库itemadded eventhandler导致的上传完成后,编辑页面保持报错的问题,错误信息为“该文档已经被编辑过 the file has been modified by...”
在文档库中添加itemadded 后,在上传文件后,会自动打开文档属性的编辑页面,在保存的时候就会报错,说这个文档已经被编辑过了.这是应为默认itemadded实践是异步执行的,会在edit页面打开之 ...
- 从web编辑器 UEditor 中单独提取图片上传,包含多图片单图片上传以及在线涂鸦功能
UEditor是由百度web前端研发部开发所见即所得富文本web编辑器,具有轻量,可定制,注重用户体验等特点,开源基于MIT协议,允许自由使用和修改代码.(抄的...) UEditor是非常好用的富文 ...
- 使用百度UMeditor富文本编辑器,修改自定义图片上传,修改源码
富文本编辑器,不多说了,这个大家应该都用到过,至于用到的什么版本,那就分很多种 CKEditor:很早以前叫FCK,那个时候也用过,现在改名了,比较流行的一个插件,国外很多公司在用 UEDITOR:百 ...
- C# 10分钟入门基于WebOffice实现在线编辑文档,实时保存到服务器(所有office,兼容WPS)
今天,他来了(weboffice在线编辑文档). 上次写了一个在线预览的博,当然,效果并不是太理想,但是紧急解决了当时的问题. 后来,小编重新查找资料,求助大牛,终于使用新的方式替换了之前的low方法 ...
- (六)在线文档编辑器的使用和数据字典(ueditor编辑器/my97datepicker日期控件)
使用ueditor编辑器注意: 1. 要把ueditor的jar包添加到WEB-INF/lib里. 2. 在做图片上传等功能时,必须重写struts的过滤器,否则图片流会被拦截程序无法得到图片. 3. ...
- Jeecg社区wiki在开放,最终能够在线看文档啦!!!
Jeecg社区wiki在开放,最终能够在线看文档啦! .! 2014-12-18 scott JEECG jeecg开源社区wiki正式启动了.方便大家看文档 訪问地址是: http://osbaba ...
- 使用swagger实现web api在线接口文档
一.前言 通常我们的项目会包含许多对外的接口,这些接口都需要文档化,标准的接口描述文档需要描述接口的地址.参数.返回值.备注等等:像我们以前的做法是写在word/excel,通常是按模块划分,例如一个 ...
随机推荐
- A. The Meaningless Game(数学)
A. The Meaningless Game time limit per test:1 second memory limit per test:256 megabytes input:stand ...
- KVM虚拟机的日常管理与配置
1. 查看KVM虚拟机配置文件及运行状态(1) KVM虚拟机默认配置文件位置: /etc/libvirt/qemu/ autostart目录是配置kvm虚拟机开机自启动目录. (2) virsh命令帮 ...
- “全栈2019”Java第六十五章:接口与默认方法详解
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...
- maven+eclipse+ssm 环境搭建和启动
该类工程环境搭建和启动方法 ------------------------------------------------------------------------------- 配置 jdk ...
- PHP内核研究 静态变量
静态变量 它可以是 静态全局变量,如果不调用unset,那么这个静态变量会一直存在,直到程序退出时才由Zend内存管理来释放 它可以是 静态局部变量:在函数里定义,函数执行完后,该静态变量不会消失 它 ...
- Python3之文本操作
文件操作示例分析: 文件操作一般要经历三个步骤: 打开文件 操作文件 关闭文件 读取操作示例: >>>f = open('test.txt', 'r') # 打开文件test.txt ...
- Review notes
- 什么是hive
Hadoop Hive概念学习系列之什么是Hive? 参考 <Hadoop大数据分析与挖掘实战>的在线电子书阅读 http://yuedu.baidu ...
- Docker安装Odoo实现快速迁移(四)
一. 安装postgres数据库 root@ubuntu-:~# docker run -d -e POSTGRES_USER=odoo -e POSTGRES_PASSWORD=odoo --nam ...
- JVM虚拟机知识点
java -version 显示JDK 版本 Java HotSpot Client:1.5版本之后,热点探测,对加载的class文件做标记,对于频繁使用的class即时编译JIT本地缓存,不再重新进 ...