首页 > 其他分享 >WordPress编辑器支持一键粘贴

WordPress编辑器支持一键粘贴

时间:2022-11-21 12:12:27浏览次数:57  
标签:ext 一键 upload fileName 编辑器 WordPress php 上传

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

1、前端引用代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <meta http-equiv="Content-Type"content="text/html; charset=utf-8"/>

 

   <title>编辑器完整版实例-1.2.6.0</title>

    <script type="text/javascript"src="ueditor.config.js"charset="utf-8"></script>

    <script type="text/javascript"src="ueditor.all.js"charset="utf-8"></script>

    <link type="text/css"rel="Stylesheet"href="WordPaster/css/WordPaster.css"/>

    <link type="text/css"rel="Stylesheet"href="WordPaster/js/skygqbox.css"/>

    <scrip ttype="text/javascript"src="WordPaster/js/json2.min.js"charset="utf-8"></script>

    <scrip ttype="text/javascript"src="WordPaster/js/jquery-1.4.min.js"charset="utf-8"></script>

    <scrip ttype="text/javascript"src="WordPaster/js/WordPaster.js"charset="utf-8"></script>

    <scrip ttype="text/javascript"src="WordPaster/js/skygqbox.js"charset="utf-8"></script>

</head>

<body>

    <textarea name="后台取值的key"id="myEditor">这里写你的初始化内容</textarea>

    <script type="text/javascript">

        var pasterMgr = new WordPasterManager();

    pasterMgr.Config["PostUrl"] = "http://localhost: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);

     var editor = 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 = "http://".$_SERVER["HTTP_HOST"]."/";

//相对路径 http://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());

?>

效果展示:

编辑

详细思路及源码

示例下载:wordpaster-vue3-cli-ueditor1.5wordpaster-vue-ueditor1.5wordpaster-asp.net-ueditor1.5xwordpaster-php-ueditor1xwordpaster-jsp-ueditor1x​

 

标签:ext,一键,upload,fileName,编辑器,WordPress,php,上传
From: https://www.cnblogs.com/zyzzz/p/16911013.html

相关文章

  • gradle-docker-plugin插件一键发布镜像
    官网地址https://bmuschko.github.io/gradle-docker-plugin/current/user-guide/#introductionSpringboot项目使用plugins{id'java'id'org.springframew......
  • WordPress编辑器支持ppt导入
    ​ 在之前在工作中遇到在富文本编辑器中粘贴图片不能展示的问题,于是各种网上扒拉,终于找到解决方案,在这里感谢一下知乎中众大神以及TheViper。通过知乎提供的思路找到粘......
  • 一键开启云原生网络安全新视界
    随着云原生的兴起,微服务、容器、kubernetes容器编排正在快速改变着企业软件架构的形态,单体架构、分布式架构、微服务架构,软件架构在持续演进的过程中,变得越来越复杂,管理和维......
  • HTML、CSS、JS实现的HTML、CSS、JS编辑器
    Atom通用代码编辑器,Github出品,基于electron​桌面应用平台,https://atom.io/,源代码:https://github.com/atom/atomVisualStudioCode通用代码编辑器,微软出品,基于electron​......
  • wordpress相关工具
    wordpress相关工具wpscanhttps://github.com/wpscanteam/wpscanhttps://wpvulndb.com/users/choose_plan注册api-tokendockerpullwpscanteam/wpscando......
  • WordPress 特色封面图像开启与使用
    wordpress特色图像可以用于分类页面或者网站首页调用文章缩略图时,指定调用某张图片,实现自定义封面的效果。WORDPRESS程序默认是不支持特色图像功能,所以我们需要开启特色图......
  • wordpress变量$current_user获取当前用户登录名、ID、信息
    1.get_currentuserinfo();此函数将当前登录用户信息赋给全局变量$current_user以及一些单独的用户信息全局变量例如$display_name,$user_email等。代码如下:<?phpglob......
  • 删除WordPress评论中的自动链接
    默认情况下,WordPress会自动为评论中的网址加上链接。这可能是有用的,但由于互联网上有大量的垃圾评论,您可能要删除此功能。要删除评论中的自动网址链接,可以打开你的主题fun......
  • 【Unity3D】Unity 脚本 ② ( Visual Studio 2019 中的 Unity 编译环境配置 | Unity 编
    文章目录​​一、VisualStudio2019中的Unity编译问题​​​​二、Unity编辑器中关联外部C#脚本编辑器​​​​三、设置游戏运行时脚本更新行为​​一、Visual......
  • 关于编辑器QScintilla(Scintilla)词法分析器工作原理的分析(实现注释区分)
    入门,首先看我这两篇博客:关于QScintilla库的入门大全正式开始,先来看看词法分析器和编辑器的关系:(注意:如果自己重写一个词法分析器,那么用的是继承另一个类 QsciLexerCustom ......