响应式文件管理器和 TinyMCE [英] Responsive File Manager and TinyMCE

查看:24
本文介绍了响应式文件管理器和 TinyMCE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Laravel v 6 应用程序中使用 响应式文件管理器 9.14.0 和 tinyMCE v 5 - 我按照教程进行设置.除了单击开始上传"按钮外,一切正常 - 我收到此错误:意外令牌<在位置 0 的 JSON 中. 这显示在后端页面的 php 错误日志中我收到了这两个错误.

I'm using Responsive File Manager 9.14.0 with tinyMCE v 5 in a Laravel v 6 App - I followed a tutorial in doing the setup. Everything works fine apart from when the button 'Start upload' is clicked - I get this error: Unexpected token < in JSON at position 0. This is displayed in the page on the back end in the php error log I get these two errors.

[05-Mar-2020 12:08:17 Europe/Rome] PHP Notice: Trying to access array offset on value of type null in /var/www/html/laratest/public/tinymce/filemanager/UploadHandler.php on line 496

[05-Mar-2020 12:08:17 Europe/Rome] PHP Notice: Trying to access array offset on value of type null in /var/www/html/laratest/public/tinymce/filemanager/UploadHandler.php on line 1429.

奇怪的是,大文件不会出现错误.另外奇怪的是,即使出现此错误,它仍然可以正常下载文件.这是我的 tinymce 配置

What is strange is that the error does not occur with large files. Also what is strange is that even though this error is given it stills downloads the file okay. Here my tinymce config

tinymce.init({
    selector: 'textarea',
    plugins: 'image code a11ychecker advcode casechange formatpainter linkchecker lists checklist media mediaembed pageembed permanentpen powerpaste table advtable tinymcespellchecker',
    toolbar: ' link image casechange checklist code formatpainter pageembed permanentpen table',
    image_title: true, 
    automatic_uploads: true,
    file_picker_types: 'image',
    external_filemanager_path:"{{url('tinymce/filemanager')}}/",
            filemanager_title:"Responsive Filemanager" ,
            external_plugins: { "filemanager" : "{{url('tinymce')}}/filemanager/plugin.min.js"},

  });

推荐答案

问题出在UploadHandler.php文件的第496行和第1429行

The problem is on line 496 and line 1429 in the file UploadHandler.php

////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////

第 496 行代码

////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////

  protected function get_unique_filename($file_path, $name, $size, $type, $err

    or,
            $index, $content_range) {
        while(is_dir($this->get_upload_path($name))) {
            $name = $this->upcount_name($name);
        }
        // Keep an existing filename if this is part of a chunked upload:
        //BELOW is line 496
        $uploaded_bytes = $this->fix_integer_overflow((int)$content_range[1]);
        while (is_file($this->get_upload_path($name))) {
            if ($uploaded_bytes === $this->get_file_size(
                    $this->get_upload_path($name))) {
                break;
            }
            $name = $this->upcount_name($name);
        }
        return $name;
    }

////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////

以及第 1429 行附近的代码

And the code around line 1429

////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////

$response = array($this->options['param_name'] => $files);
$name = $file_name ? $file_name : $upload['name'][0];
$res = $this->generate_response($response, $print_response);
if(is_file($this->get_upload_path($name))){
// BELOW IS LINE 1429
    $uploaded_bytes = $this->fix_integer_overflow((int)$content_range[1]);
    $totalSize = $this->get_file_size($this->get_upload_path($name));
    if ($totalSize - $uploaded_bytes - $this->options['readfile_chunk_size'] < 0) {
        $this->onUploadEnd($res);
    }else{
        $this->head();
        $this->body(json_encode($res));
    }
}else{
    $this->head();
    $this->body(json_encode($res));
}

问题在于当上传的文件没有被分块时 $content_range[1] 的值.需要检查 $content_range[1] 的值是否已设置.

The problem is with the value of $content_range[1] when the file being uploaded is not being chunked. The value of $content_range[1] needs to be checked to see if its set.

以下是对抛出错误的两个代码摘录的解决方案.首先是第 496 行附近的代码

Below is the solution to the two extracts of code that have been throwing the error. First the code around line 496

   protected function get_unique_filename($file_path, $name, $size, $type, $error,
            $index, $content_range) {
        while(is_dir($this->get_upload_path($name))) {
            $name = $this->upcount_name($name);
        }
        // Keep an existing filename if this is part of a chunked upload:  
        if(isset($content_range[1])){
             $uploaded_bytes = $this->fix_integer_overflow((int)$content_range[1]);
        }

        while (is_file($this->get_upload_path($name))) {
            if(isset($uploaded_bytes)){
            if ($uploaded_bytes === $this->get_file_size(
                    $this->get_upload_path($name))) {
                break;
            }
            }
            $name = $this->upcount_name($name);
        }

        return $name;
    }

以及大约 1429 的第二位代码.

And the second bit code around 1429.

$response = array($this->options['param_name'] => $files);
$name = $file_name ? $file_name : $upload['name'][0];
$res = $this->generate_response($response, $print_response);
if(is_file($this->get_upload_path($name))){
    if(isset($content_range[1])){
     $uploaded_bytes = $this->fix_integer_overflow((int)$content_range[1]);
    }
    else{
     $uploaded_bytes = 0;
    }
    $totalSize = $this->get_file_size($this->get_upload_path($name));


    if ($totalSize - $uploaded_bytes - $this->options['readfile_chunk_size'] < 0) {

           $this->onUploadEnd($res);

    }else{
        $this->head();
        $this->body(json_encode($res));
    }
}else{
    $this->head();
    $this->body(json_encode($res));
}
return $res;

这篇关于响应式文件管理器和 TinyMCE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆