Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.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_Html_Tinymce - Fatal编程技术网

Javascript tinymce使用文件浏览器添加图像

Javascript tinymce使用文件浏览器添加图像,javascript,php,html,tinymce,Javascript,Php,Html,Tinymce,我在我的博客上有一个添加帖子功能的代码,我有一个允许选择文件的按钮,但它不起作用。有什么帮助吗 tinymce.init({ selector: "textarea", plugins: [ "advlist autolink lists link image charmap print preview anchor", "searchreplace visualblocks code

我在我的博客上有一个添加帖子功能的代码,我有一个允许选择文件的按钮,但它不起作用。有什么帮助吗

      tinymce.init({

          selector: "textarea",
          plugins: [
              "advlist autolink lists link image charmap print preview anchor",
              "searchreplace visualblocks code fullscreen",
              "insertdatetime media table contextmenu paste"
          ],
          toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",

          file_browser_callback : 'myFileBrowser'


      });


我希望这会对你有所帮助

 tinymce.init({
      selector: 'textarea',  // change this value according to your HTML
      images_upload_handler: function (blobInfo, success, failure) {
        var xhr, formData;

        xhr = new XMLHttpRequest();
        xhr.withCredentials = false;
        xhr.open('POST', 'postAcceptor.php');

        xhr.onload = function() {
          var json;

          if (xhr.status != 200) {
            failure('HTTP Error: ' + xhr.status);
            return;
          }

          json = JSON.parse(xhr.responseText);

          if (!json || typeof json.location != 'string') {
            failure('Invalid JSON: ' + xhr.responseText);
            return;
          }

          success(json.location);
        };

        formData = new FormData();
        formData.append('file', blobInfo.blob(), blobInfo.filename());

        xhr.send(formData);
      }
    });
欲知详情


您得到了什么样的行为,您期望得到什么?它当前具有“通过文件选择添加图像”功能,但当我单击它时,它不会执行任何操作。我希望它能够浏览文件,并将它们添加到文本字段。
var fileUploadUrl = "{{route('fileUploadEditor')}}";

tinymce.init({
    selector: 'textarea',  // change this value according to your HTML
    images_upload_handler: function (blobInfo, success, failure) {
    var xhr, formData;

    xhr = new XMLHttpRequest();
    xhr.withCredentials = false;
    xhr.open('POST',fileUploadUrl);

    xhr.onload = function() {
      var json;

      if (xhr.status != 200) {
        failure('HTTP Error: ' + xhr.status);
        return;
      }

      json = JSON.parse(xhr.responseText);

      if (!json || typeof json.location != 'string') {
        failure('Invalid JSON: ' + xhr.responseText);
        return;
      }

      success(json.location);
    };

    formData = new FormData();
    formData.append('file', blobInfo.blob(), blobInfo.filename());

    xhr.send(formData);
  }
});