laravel - 响应式文件管理器和 TinyMCE
问题描述
我在 Laravel v 6 应用程序中使用带有 tinyMCE v 5 的响应式文件管理器9.14.0 - 我按照教程进行设置。除了单击“开始上传”按钮外,一切正常 - 我收到此错误:位置 0 处的 JSON 中的意外令牌 <。这显示在 php 错误日志的后端页面中,我收到这两个错误。
[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配置
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 行
///////////////////////////////////////// ////////////////////////////
第 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 行的代码
///////////////////////////////////////// ///////////////////////////
$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] 的值以查看其是否设置。
以下是两个引发错误的代码摘录的解决方案。首先是第 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 左右。
$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;
推荐阅读
- redirect - keycloak 重定向到 https://localhost 而不是 http://localhost
- amcharts4 - Amchart 标签和标题位置不正确
- javascript - 如何在 SAP 混合应用程序中包含具有相对路径的集合?
- elm - 如何从 elm 对象中获取特定的键值对
- python - 如何在一个请求中收集所有可用的 Pod 指标
- sql - SQL如何查询总计和小计
- regex - 我的公式只保留一个单词,空格后没有任何内容
- javascript - 将每个对象属性乘以 2 并从结果中创建新对象
- javascript - 使用一个链接滚动两列
- linux - 从 LINUX 特定目录下的文件中查找特定字符串