如何实现将Word文档中的图片粘贴到CKEditor编辑器中的实例?

2026-03-30 14:331阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计929个文字,预计阅读时间需要4分钟。

如何实现将Word文档中的图片粘贴到CKEditor编辑器中的实例?

如何实现Ueditor批量上传Word文档?

1. 前端引用Ueditor代码:PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/x1/DTD/x1-transitional.dtd>

2.在Ueditor实例化时,配置上传参数:

javascriptvar editor=UE.getEditor('editor');editor.addListener('beforeInsertImage', function (t, arg) { // 处理批量上传Word文档的逻辑});

3.在`beforeInsertImage`事件中,添加批量上传Word文档的功能:

javascripteditor.addListener('beforeInsertImage', function (t, arg) { // 使用iframe或window.open打开一个上传Word文档的页面 var uploadWindow=window.open('upload-word.', 'uploadWindow', 'width=600,height=400'); uploadWindow.onload=function () { // 监听上传窗口的回调 uploadWindow.document.getElementById('uploadForm').onsubmit=function () { // 获取上传的Word文档信息 var wordFile=this.wordFile.files[0]; // 调用后端接口上传Word文档 // ... }; };});

如何做到 ueditor批量上传word图片?

1、前端引用代码

如何实现将Word文档中的图片粘贴到CKEditor编辑器中的实例?

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">​

<htmlxmlns="www.w3.org/1999/xhtml">​

<head>​

<metalocalhost:81/WordPaster2/WordPasterUEditor1x/php/upload.php"​

pasterMgr.Load();//加载控件


UE.getEditor('myEditor',{onready:function(){//创建一个编辑器实例

pasterMgr.SetEditor(this);

}});

</script>​

</body>​

</html>​

请求

文件上传的默认请求是一个文件,作为具有“upload”字段的表单数据。

响应:文件已成功上传

当文件成功上传时的JSON响应:

uploaded-设置为1。

fileName -上传文件的名称。

url -上传文件的URL。

响应:文件无法上传

uploaded-设置为0。

error.message -要显示给用户的错误消息。

2、粘贴word里面的图片路径是fill://D 这种格式 我理解这种是非浏览器安全的 许多浏览器也不支持

目前项目是用了一种变通的方式:

先把word上传到后台 、poi解析、存储图片 、转换html、替换图片、放到富文本框里显示

(富文本显示有个坑:没找到直接给富文本赋值的方法 要先销毁 记录下

success :function(data) {

$('#content').attr('value',data.imagePath);

vareditor = CKEDITOR.instances["content"];//你的编辑器的"name"属性的值

if(editor) {

editor.destroy(true);//销毁编辑器

}

CKEDITOR.replace('content');//替换编辑器,editorID为ckeditor的"id"属性的值

$("#content").val(result);//对editor赋值

//CKEDITOR.instances.contentCkeditor.setData($("#content").text());

}

3.接收上传的图片并保存在服务端

<?php

ob_start();

//201201/10

$timeDir =date("Ym")."/".date("d");

$uploadDir =dirname(__FILE__).'/upload/'.$timeDir;

$curDomain = "".$_SERVER["HTTP_HOST"]."/";

//相对路径 www.ncmem.com/upload/2012-1-10/

$relatPath = $curDomain ."WordPaster2/WordPasterUEditor1x/php/upload/" . $timeDir . "/";


//自动创建目录。upload/2012-1-10

if(!is_dir($uploadDir))

{

mkdir($uploadDir,0777,true);

}


//如果PHP页面为UTF-8编码,请使用urldecode解码文件名称

//$fileName = urldecode($_FILES['postedFile']['name']);

//如果PHP页面为GB2312编码,则可直接读取文件名称

$fileName = $_FILES['file']['name'];

$tmpName = $_FILES['file']['tmp_name'];


//取文件扩展名jpg,gif,bmp,png

$path_parts =pathinfo($fileName);

$ext = $path_parts["extension"];

$ext =strtolower($ext);//jpg,png,gif,bmp


//只允许上传图片类型的文件

if($ext == "jpg"

|| $ext == "jpeg"

|| $ext == "png"

|| $ext == "gif"

|| $ext == "bmp")

{

//年_月_日_时分秒毫秒.jpg

$saveFileName = $fileName;


//xxx/2011_05_05_091250000.jpg

$savePath = $uploadDir . "/" . $saveFileName;


//另存为新文件名称

if (!move_uploaded_file($tmpName,$savePath))

{

exit('upload error!' . "文件名称:" .$fileName . "保存路径:" . $savePath);

}

}


//输出图片路径

//$_SERVER['HTTP_HOST']localhost:81

//$_SERVER['REQUEST_URI'] /FCKEditor2.4.6.1/php/test.php

$reqPath =str_replace("upload.php","",$_SERVER['REQUEST_URI']);

echo $relatPath .$saveFileName;

header('Content-type: text/html; charset=utf-8');

header('Content-Length: ' .ob_get_length());

?>

效果展示:

标签:实例

本文共计929个文字,预计阅读时间需要4分钟。

如何实现将Word文档中的图片粘贴到CKEditor编辑器中的实例?

如何实现Ueditor批量上传Word文档?

1. 前端引用Ueditor代码:PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/x1/DTD/x1-transitional.dtd>

2.在Ueditor实例化时,配置上传参数:

javascriptvar editor=UE.getEditor('editor');editor.addListener('beforeInsertImage', function (t, arg) { // 处理批量上传Word文档的逻辑});

3.在`beforeInsertImage`事件中,添加批量上传Word文档的功能:

javascripteditor.addListener('beforeInsertImage', function (t, arg) { // 使用iframe或window.open打开一个上传Word文档的页面 var uploadWindow=window.open('upload-word.', 'uploadWindow', 'width=600,height=400'); uploadWindow.onload=function () { // 监听上传窗口的回调 uploadWindow.document.getElementById('uploadForm').onsubmit=function () { // 获取上传的Word文档信息 var wordFile=this.wordFile.files[0]; // 调用后端接口上传Word文档 // ... }; };});

如何做到 ueditor批量上传word图片?

1、前端引用代码

如何实现将Word文档中的图片粘贴到CKEditor编辑器中的实例?

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">​

<htmlxmlns="www.w3.org/1999/xhtml">​

<head>​

<metalocalhost:81/WordPaster2/WordPasterUEditor1x/php/upload.php"​

pasterMgr.Load();//加载控件


UE.getEditor('myEditor',{onready:function(){//创建一个编辑器实例

pasterMgr.SetEditor(this);

}});

</script>​

</body>​

</html>​

请求

文件上传的默认请求是一个文件,作为具有“upload”字段的表单数据。

响应:文件已成功上传

当文件成功上传时的JSON响应:

uploaded-设置为1。

fileName -上传文件的名称。

url -上传文件的URL。

响应:文件无法上传

uploaded-设置为0。

error.message -要显示给用户的错误消息。

2、粘贴word里面的图片路径是fill://D 这种格式 我理解这种是非浏览器安全的 许多浏览器也不支持

目前项目是用了一种变通的方式:

先把word上传到后台 、poi解析、存储图片 、转换html、替换图片、放到富文本框里显示

(富文本显示有个坑:没找到直接给富文本赋值的方法 要先销毁 记录下

success :function(data) {

$('#content').attr('value',data.imagePath);

vareditor = CKEDITOR.instances["content"];//你的编辑器的"name"属性的值

if(editor) {

editor.destroy(true);//销毁编辑器

}

CKEDITOR.replace('content');//替换编辑器,editorID为ckeditor的"id"属性的值

$("#content").val(result);//对editor赋值

//CKEDITOR.instances.contentCkeditor.setData($("#content").text());

}

3.接收上传的图片并保存在服务端

<?php

ob_start();

//201201/10

$timeDir =date("Ym")."/".date("d");

$uploadDir =dirname(__FILE__).'/upload/'.$timeDir;

$curDomain = "".$_SERVER["HTTP_HOST"]."/";

//相对路径 www.ncmem.com/upload/2012-1-10/

$relatPath = $curDomain ."WordPaster2/WordPasterUEditor1x/php/upload/" . $timeDir . "/";


//自动创建目录。upload/2012-1-10

if(!is_dir($uploadDir))

{

mkdir($uploadDir,0777,true);

}


//如果PHP页面为UTF-8编码,请使用urldecode解码文件名称

//$fileName = urldecode($_FILES['postedFile']['name']);

//如果PHP页面为GB2312编码,则可直接读取文件名称

$fileName = $_FILES['file']['name'];

$tmpName = $_FILES['file']['tmp_name'];


//取文件扩展名jpg,gif,bmp,png

$path_parts =pathinfo($fileName);

$ext = $path_parts["extension"];

$ext =strtolower($ext);//jpg,png,gif,bmp


//只允许上传图片类型的文件

if($ext == "jpg"

|| $ext == "jpeg"

|| $ext == "png"

|| $ext == "gif"

|| $ext == "bmp")

{

//年_月_日_时分秒毫秒.jpg

$saveFileName = $fileName;


//xxx/2011_05_05_091250000.jpg

$savePath = $uploadDir . "/" . $saveFileName;


//另存为新文件名称

if (!move_uploaded_file($tmpName,$savePath))

{

exit('upload error!' . "文件名称:" .$fileName . "保存路径:" . $savePath);

}

}


//输出图片路径

//$_SERVER['HTTP_HOST']localhost:81

//$_SERVER['REQUEST_URI'] /FCKEditor2.4.6.1/php/test.php

$reqPath =str_replace("upload.php","",$_SERVER['REQUEST_URI']);

echo $relatPath .$saveFileName;

header('Content-type: text/html; charset=utf-8');

header('Content-Length: ' .ob_get_length());

?>

效果展示:

标签:实例