Ueditor文件上传问题

我们在做一些网站是会遇到,要有上传文件一类的事情。

我发现百度的富文本编辑器带上传功能,但是没有办法给后台传递我们要的参数。

先在ueditor.all.js中找到, me.execCommand(‘insertHtml‘, html);

在它下面添加: me.fireEvent(‘afterUpfile‘,filelist);

此时,我们就可以在前台监听上传了。

ps:filelist你联系上文,我们可以知道就是我们要的文件信息数组,有后台返回的。

在前台添加,uploadEditor为编辑器对象实体。

1 uploadEditor.ready(function() {
2             uploadEditor.addListener("afterUpfile", _afterUpfile);
3         });

_afterUpfile,为监听函数,就是我们自己的事物了。

如:

 1  // 监听函数
 2         function _afterUpfile(t, result) {
 3             var fileHtml = ‘‘;
 4             var str;
 5             for (var i in result) {
 6                 NAME[i] = result[i].title;
 7                 URL[i] = result[i].url;
 8                 str = ‘文件名:  ‘ + result[i].title + ‘<br/>‘;
 9                 fileHtml += ‘<li>‘ + str + ‘</li>‘;
10             }
11             document.getElementById(‘fileList‘).innerHTML = fileHtml;
12         }

下面是一个完整的测试页面哦。

 1 <!doctype html>
 2 <html lang="zh-cn">
 3
 4 <head>
 5     <meta charset="UTF-8">
 6     <title>外部调用UEditor的多图上传和附件上传</title>
 7     <script type="text/javascript" charset="utf-8" src="ueditor.config.js"></script>
 8     <script type="text/javascript" charset="utf-8" src="ueditor.all.js"></script>
 9     <style>
10     ul {
11         display: inline-block;
12         width: 100%;
13         margin: 0;
14         padding: 0;
15     }
16
17     li {
18         list-style-type: none;
19         margin: 5px;
20         padding: 0;
21     }
22     </style>
23 </head>
24
25 <body>
26     <h1>外部调用UEditor的多图上传和附件上传示例</h1>
27     <button type="button" id="j_upload_file_btn">附件上传</button>
28     <ul id="upload_file_wrap"></ul>
29     <!-- 加载编辑器的容器 -->
30     <textarea id="uploadEditor" style="display: none;"></textarea>
31     <!-- 使用ue -->
32     <script type="text/javascript">
33     // 实例化编辑器,这里注意配置项隐藏编辑器并禁用默认的基础功能。
34     var uploadEditor = UE.getEditor("uploadEditor", {
35         isShow: false,
36         focus: false,
37         enableAutoSave: false,
38         autoSyncData: false,
39         autoFloatEnabled: false,
40         wordCount: false,
41         sourceEditor: null,
42         scaleEnabled: true,
43         toolbars: [
44             ["insertimage", "attachment"]
45         ]
46     });
47
48     // 监听多图上传和上传附件组件的插入动作
49     uploadEditor.ready(function() {
50         uploadEditor.addListener("afterUpfile",  function(t, result) {
51                 alert(111);
52                 var fileHtml = ‘‘;
53                 for (var i in result) {
54                     fileHtml += ‘<li><a href="‘ + result[i].url + ‘" target="_blank">‘ + result[i].url + ‘</a></li>‘;
55                 }
56                 document.getElementById(‘upload_file_wrap‘).innerHTML = fileHtml;
57             });
58     });
59
60     document.getElementById(‘j_upload_file_btn‘).onclick = function() {
61         var dialog = uploadEditor.getDialog("attachment");
62         dialog.title = ‘附件上传‘;
63         dialog.render();
64         dialog.open();
65     };
66
67
68
69     // 附件上传
70     function _afterUpfile(t, result) {
71         var fileHtml = ‘‘;
72         for (var i in result) {
73             fileHtml += ‘<li><a href="‘ + result[i].url + ‘" target="_blank">‘ + result[i].url + ‘</a></li>‘;
74         }
75         document.getElementById(‘upload_file_wrap‘).innerHTML = fileHtml;
76     }
77     </script>
78 </body>
79
80 </html>

这是在网上找的,源地址以找不到了。

但是在这里要感谢这些分享他们代码和心得的coders。

时间: 2024-08-24 06:42:42

Ueditor文件上传问题的相关文章

ueditor 文件上传的分析和总结

正式开始之前,先写两个常用又容易被我忘掉的文件和流相互转化的方法. 1,文件转流 FileStream fs = new FileStream(filename,FileMode.Open,FileAccess.Read); byte[] infbytes = new byte[(int)fs.Length]; fs.Read(infbytes, 0, infbytes.Length); fs.Close(); return infbytes; 2,流转文件 FileStream fs = ne

将Ueditor文件上传至OSS

前人已经将ueditor集成了oss,本次是作为记录 1:点击到下载页面 下载并按照文档安装 2:将 com.zip(在UEditor-for-aliyun-OSS-master\ueditor\src\main\java)拷贝到你的src下 3: 安装原作者文档配置OSSKey.properties,注意:源文档少了ossCliendEndPoint,加上即可,具体如下: 1 # default value false 2 useStatus=true 3 4 # ALIYUN OSS buc

Ueditor 前后端分离实现文件上传到独立服务器

关于Ueditor 前后端分离实现文件上传到独立服务器,在网上搜索确实遇到大坑,不过还好遇到了 虚若影 最终实现了,在此感谢!虚若影的原文博客网址:http://www.cnblogs.com/hpnet/p/6290452.html 具体项目:如下截图 1.在本地IIS 中添加网站 ueditorweb.com .ueditortest.com . testweb (注意应用程序池要选择.net的版本) 2.hosts文件中添加 127.0.0.1  ueditorweb.com  uedit

UEditor Flash文件上传-crossdomain.xml文件配置

在使用UEditor富文本时,如果客户端的浏览器是低版本浏览器,如IE7.IE8等,UEditor的文件上传方式将会使用flash方式上传而不是html5,而flash在跨域时唯一的限制策略就是crossdomain.xml文件,该文件限制了flash是否可以跨域读写数据以及允许从什么地方跨域读写数据. 从UEditor官方文档上看,如果使用flash方式上传文件,那么只需要设置如下即可: 但实际在IE7.IE8环境下该文件被正确请求到后仍然无法正确上传文件,而是报出“http请求错误”信息.

Ueditor结合七牛云及百度云存储(JAVA版,ueditor-1.4.3)实现图片文件上传

[前言] 之前研究了ueditor直接上传图片文件到七牛云以及百度云存储,见下面两篇文章: http://uikoo9.com/blog/detail/ueditor-for-bcs http://uikoo9.com/blog/detail/ueditor-for-qiniu 另外还有一篇ueditor-1.4.3-jsp的使用教程: http://uikoo9.com/blog/detail/how-to-use-ueditor 今天实现了ueditor可配置选择上传到七牛还是百度还是本地,

百度开源富文本编辑器 UEditor配置:图片上传和文件上传独立使用方法

使用UEditor编辑器自带的插件实现图片上传和文件上传功能,这里通过配置UEditor单独使用其内置的第三方插件swfupload来实现图片和文件的上传,通过对UEditor配置轻松实现图片批量上传,文件披批量上传 第一步:先配置UEditor <script src="ueditor/ueditor.config.js"></script> <script src="ueditor/ueditor.all.min.js">&l

网站漏洞修复之UEditor漏洞 任意文件上传漏洞 2018 .net新

UEditor于近日被曝出高危漏洞,包括目前官方UEditor 1.4.3.3 最新版本,都受到此漏洞的影响,ueditor是百度官方技术团队开发的一套前端编辑器,可以上传图片,写文字,支持自定义的html编写,移动端以及电脑端都可以无缝对接,自适应页面,图片也可以自动适应当前的上传路径与页面比例大小,一些视频文件的上传,开源,高效,稳定,安全,一直深受站长们的喜欢. 百度的UEditor文本编辑器,近几年很少被曝出漏洞,事情没有绝对的,总会有漏洞,这次被曝出的漏洞是.net版本的,其他的php

ueditor图片上传配置

ueditor图片上传配置文件为ueditor/php/config.json /* 上传图片配置项 */ "imageActionName": "uploadimage", /* 运行上传图片的action名称 */ "imageFieldName": "upfile", /* 提交的图片表单名称 */ "imageMaxSize": 2048000, /* 上传限制大小,单位B */ "ima

百度编辑器ueditor给上传的图片添加水印

百度编辑器本身是没有为上传图片添加水印的功能,想要在上传的时候添加图片水印,也很简单.以 ueditor 1.2.6 为例,打开php目录下面的imageUp.php文件,查找"$info = $up->getFileInfo();",在这句代码的下面加入以下代码: /* 添加水印 start */ $water_img = "watermark.png"; //水印文件(替这里换成你要的水印) $img_min_w = 350; //添加水印需要图片最小达到