如何解决TinyMCE上传图片后路径错误
TinyMCE版本:4.6.5
我的表单和tinyMCE编辑器正在'public_html / adm'方向工作,我正在尝试将图像上传到'public_html / images / upload'。
tinyMCE初始化
tinymce.init({
selector: '.mytextarea',plugins: 'advlist autolink link lists charmap print preview media textcolor hr table image code powerpaste',toolbar: 'undo redo | insert | styleselect | bold italic forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent hr | link image table code ',powerpaste_word_import: "prompt",menubar: false,min_height: 300,entity_encoding : "raw",// enable title field in the Image dialog
image_title: true,// enable automatic uploads of images represented by blob or data URIs
automatic_uploads: true,// URL of our upload handler (for more details check: https://www.tinymce.com/docs/configure/file-image-upload/#images_upload_url)
images_upload_url: 'postAcceptor.php',// here we add custom filepicker only to Image dialog
file_picker_types: 'image',.
.
.
postAcceptor.php
<?php
$imageFolder = "../images/upload/";
reset ($_FILES);
$temp = current($_FILES);
if (is_uploaded_file($temp['tmp_name'])){
if (preg_match("/([^\w\s\d\-_~,;:\[\]\(\).])|([\.]{2,})/",$temp['name'])) {
header("HTTP/1.0 500 Invalid file name.");
return;
}
if (!in_array(strtolower(pathinfo($temp['name'],PATHINFO_EXTENSION)),array("gif","jpg","png"))) {
header("HTTP/1.0 500 Invalid extension.");
return;
}
$filename = md5(date('YmdHis')).'.jpg';
$file = $imageFolder.$filename;
move_uploaded_file($temp['tmp_name'],$file);
echo json_encode(array('location' => $file));
} else {
header("HTTP/1.0 500 Server Error");
}
?>
上传图片后,它会像这样附加在文本区域上。
<p><img title="logo.png" src="../images/upload/0a13617f5d569df6c616578df855c92a.jpg" alt="" width="335" height="292" /></p>
问题是我的图像无法正确渲染,除非我这样更改图像路径。
<img title="logo.png" src="../../images/upload/0a13617f5d569df6c616578df855c92a.jpg" alt="" width="335" height="292" />
解决方法
您可以使用images_upload_base_path
配置选项来添加从已配置的images_upload_url
返回的URL:
https://www.tiny.cloud/docs-4x/configure/file-image-upload/#images_upload_base_path
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。