【问题标题】:Tinimce 4 image upload throwing HTTP Error: 404Tinymce 4 图片上传引发 HTTP 错误:404
【发布时间】:2018-01-17 07:55:13
【问题描述】:

我正在使用 tinymce 4 上传示例中的图片,在选择要上传的图片后,我收到“HTTP 错误:404”消息。

我已经使用发布图像文件测试了示例 postAcceptor.php,它可以工作。 在发布图片的结果中,我收到了 JSON 响应:

{"location":"/home/mylogin/domains/mydomain.com/public_html/projects/projectname/img/gallery/422.jpg"}

那些额外的斜线是正确的吗? 我的初始化代码:

      tinymce.init({
            selector: 'textarea.content',
            plugins: 'image code',
            toolbar: 'undo redo | link image | code',
            // enable title field in the Image dialog
            image_title: true,
            automatic_uploads: true,

            images_upload_url: 'postAcceptor.php',
            images_upload_base_path: '/img/gallery/',
            images_upload_credentials: true,

            file_picker_types: 'image',

            // and here's our custom image picker
            file_picker_callback: function(cb, value, meta) {
                var input = document.createElement('input');
                input.setAttribute('type', 'file');
                input.setAttribute('accept', 'image/*');
                input.onchange = function() {
                    var file = this.files[0];

                    var reader = new FileReader();
                    reader.readAsDataURL(file);
                    reader.onload = function () {
                        var id = 'blobid' + (new Date()).getTime();
                        var blobCache =  tinymce.activeEditor.editorUpload.blobCache;
                        var base64 = reader.result.split(',')[1];
                        var blobInfo = blobCache.create(id, file, base64);
                        blobCache.add(blobInfo);
                        cb(blobInfo.blobUri(), { title: file.name });
                    };
                };

                input.click();
            }
        });

【问题讨论】:

    标签: javascript tinymce tinymce-4 image-upload


    【解决方案1】:

    404是由于

    引起的
    images_upload_url: 'postAcceptor.php',
    

    我已经改成

    images_upload_url: './js/tinymce/postAcceptor.php',
    

    工作就像一个魅力..

    【讨论】:

      【解决方案2】:

      您返回的 JSON 确实看起来像服务器硬盘上的位置。该位置被转换为图像的src 属性,因此它需要是允许浏览器通过网络服务器获取图像的 URL。

      【讨论】:

      • 还是一样。将其更改为普通 URL,现在我得到: {"location":"http:\/\/localhost\/projectname\/img\/gallery\/422.jpg"}
      • 在编辑器中处理图像 src 时会产生什么结果?您通常不会在返回值中包含协议或主机名。
      • 您返回的内容必须是有效的 URL。如果浏览器无法使用您返回的内容,则需要更改您返回的内容。
      猜你喜欢
      • 1970-01-01
      • 2013-09-02
      • 2015-11-15
      • 1970-01-01
      • 2020-12-19
      • 1970-01-01
      • 1970-01-01
      • 2018-11-01
      • 1970-01-01
      相关资源
      最近更新 更多