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> 

texteditor

问题是我的图像无法正确渲染,除非我这样更改图像路径。

<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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...