Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript TinyMCE上传图像后路径错误_Javascript_Php_Tinymce_Tinymce 4 - Fatal编程技术网

Javascript TinyMCE上传图像后路径错误

Javascript TinyMCE上传图像后路径错误,javascript,php,tinymce,tinymce-4,Javascript,Php,Tinymce,Tinymce 4,TinyMCE版本:4.6.5 我的表单和tinyMCE编辑器正致力于“public_html/adm”方向,我正在尝试将图像上传到“public_html/images/upload” tinyMCE init tinymce.init({ selector: '.mytextarea', plugins: 'advlist autolink link lists charmap print preview media textcolor hr table im

TinyMCE版本:4.6.5

我的表单和tinyMCE编辑器正致力于“public_html/adm”方向,我正在尝试将图像上传到“public_html/images/upload”

tinyMCE init

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" />

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

<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\u upload\u base\u路径
配置选项预先发送从已配置的
images\u upload\u url
返回的url: