php kingeditor 相对路径,kindeditor 图片上传后生成包含域名的完整路径

默认使用kindeditor上传的本地图片会生成一个相对于当前域的相对路径,本文希望上传图片后生成包含域名的完整路径

关键在于初始化kindeditor时指定以下参数:

打开kindeditor.js 文件,

搜索 urlType

K.options = {

designMode: true,

fullscreenMode: false,

filterMode: true,

wellFormatMode: true,

shadowMode: true,

loadStyleMode: true,

basePath: K.basePath,

themesPath: K.basePath + 'themes/',

langPath: K.basePath + 'lang/',

pluginsPath: K.basePath + 'plugins/',

themeType: 'default',

langType: 'zh-CN',

urlType: 'domain',

newlineTag: 'p',

resizeType: 2,

syncType: 'form',

pasteType: 2,

dialogAlignType: 'page',

useContextmenu: true,

fullscreenShortcut: false,

bodyClass: 'ke-content',

indentChar: '\t',

cssPath: '',

cssData: '',

minWidth: 650,

minHeight: 100,

minChangeSize: 50,

zIndex: 811213,

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'

],

noDisableItems: ['source', 'fullscreen'],

colorTable: [

['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],

['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],

['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],

['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']

],

fontSizeTable: ['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px'],

htmlTags: {

font: ['id', 'class', 'color', 'size', 'face', '.background-color'],

span: [

'id', 'class', '.color', '.background-color', '.font-size', '.font-family', '.background',

'.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'

],

div: [

'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color',

'.background-color', '.font-size', '.font-family', '.font-weight', '.background',

'.font-style', '.text-decoration', '.vertical-align', '.margin-left'

],

table: [

'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',

'.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',

'.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',

'.width', '.height', '.border-collapse'

],

'td,th': [

'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',

'.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',

'.font-style', '.text-decoration', '.vertical-align', '.background', '.border'

],

a: ['id', 'class', 'href', 'target', 'name'],

embed: ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess', 'wmode'],

img: ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],

'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6': [

'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',

'.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'

],

pre: ['id', 'class'],

hr: ['id', 'class', '.page-break-after'],

'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del': ['id', 'class'],

iframe: ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']

},

layout: '

'

};

改变站内本地URL,可设置”“、”relative”、”absolute”、”domain”。空为不修改URL,relative为相对路径,absolute为绝对路径,domain为带域名的绝对路径。

数据类型: String

默认值: “”

让urlType=’domain’

打赏

ff7332c9d8833ec3435fe3dc38de7de3.png

d954b0e6ab9d313a5e1b698d19023135.png微信扫一扫,打赏作者吧~

如果本篇文章对您有帮助,欢迎向博主进行赞助,赞助时请写上您的用户名。

支付宝直接捐助帐号oracle_lee@qq.com 感谢支持!

喜欢 (0)or分享 (0)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
KindEditor是一款基于JavaScript的富文本编辑器,它可以方便地集成到网站,并支持图片上传功能。在Spring Boot实现KindEditor图片上传可以按照以下步骤进行: 1. 在Spring Boot添加以下依赖: ```xml <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.4</version> </dependency> ``` 2. 创建一个Controller用于处理图片上传请求,代码如下: ```java @RestController @RequestMapping("/upload") public class FileUploadController { @PostMapping("/image") public String uploadImage(HttpServletRequest request) throws Exception { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; MultipartFile file = multipartRequest.getFile("imgFile"); String filename = file.getOriginalFilename(); String suffix = filename.substring(filename.lastIndexOf(".") + 1); String newFilename = UUID.randomUUID().toString() + "." + suffix; String savePath = "D:/upload/images/" + newFilename; // 上传文件保存路径,根据实际情况修改 File destFile = new File(savePath); if (!destFile.getParentFile().exists()) { destFile.getParentFile().mkdirs(); } file.transferTo(destFile); String url = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + "/upload/images/" + newFilename; // 图片访问URL,根据实际情况修改 return "{\"error\":0,\"url\":\"" + url + "\"}"; } } ``` 3. 在HTML页面集成KindEditor,并设置图片上传的请求地址,代码如下: ```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>KindEditor图片上传示例</title> <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/kindeditor/4.1.11/kindeditor-all.min.css" /> <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script src="https://cdn.bootcdn.net/ajax/libs/kindeditor/4.1.11/kindeditor-all.min.js"></script> </head> <body> <textarea id="editor"></textarea> <script> KindEditor.ready(function(K) { K.create('#editor', { uploadJson: '/upload/image', allowFileManager: false }); }); </script> </body> </html> ``` 4. 启动Spring Boot应用,访问HTML页面即可进行图片上传上传的图片会保存在指定的路径,并返回图片的访问URL给KindEditor进行显示。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值