Khắc phục lỗi liên quan tới responsive file manage rfm v14 resolve errors on rfm
Bao gồm: Fatal error: Uncaught ValueError: mb_http_input(): , syntaxerror: unexpected token is not valid JSON responsive file manage, thumb image
Bài viết sử dụng song ngữ (this article using 2 language)
Và giải quyết các lỗi liên quan tới rfm, các bạn đọc và xem xét lỗi của mình đang gặp phải (and solve some errors related to rfm)
1. Fatal error: Uncaught ValueError: mb_http_input(): Argument #1 ($type) must be one of "G", "P", "C", "S", "I", or "L" in
Với lỗi trên thì các bạn sửa như sau (For the above error, you can fix it as follows):
/filemanager/config/config.php at line 9
mb_http_input('UTF-8'); →mb_http_input() ;
2. Lỗi không hiện thị thumb của ảnh (cannot show thumb image)
Ảnh “thumb rfm error” không còn lưu được trên máy chủ.
/filemanager/include/php_image_magician.php line 2791
Đổi (change)
if(!is_resource($this->imageResized))
thành (into)
if(!is_resource($this->imageResized) && !($this->imageResized instanceof \GdImage))
Nếu không được thì thực hiện thêm bước sau (if it not ok, do more step)
/filemanager /dialog.php line 1159
<img class="<?php echo $show_original ? "original" : "" ?><?php echo $is_icon_thumb ? " icon" : "" ?>" data-src=" php echo $src_thumb;?>">
Thêm domain của bạn vào như dòng code bên dưới, nếu kết nối ssl thì thêm https, ngược lại thì http (add your domain here with https or http as sample below)
thành (into)
<img class="<?php echo $show_original ? "original" : "" ?><?php echo $is_icon_thumb ? " icon" : "" ?>" data-src="https://your_domain/<?php echo $src_thumb;?>">
Và thực hiện tương tự với line 1168 (repeat such as line 1168)
<img class="<?php echo $show_original_mini ? "original" : "" ?><?php echo $is_icon_thumb_mini ? " icon" : "" ?>" data-src=" php echo $mini_src;?>">
thành (change into)
<img class="<?php echo $show_original_mini ? "original" : "" ?><?php echo $is_icon_thumb_mini ? " icon" : "" ?>" data-src=" https://your_domain/<?php echo $mini_src;?>">
Nếu không có ảnh trong khung iframe thì các bạn config về thư mục upload ảnh (if it dont have any image in frame, please config upload folder such as image below)
3. Lỗi (error): SyntaxError: Unexpected token '<', "<br /> <b>"... is not valid JSON
Ảnh “SyntaxError: Unexpected token... is not valid JSON” không còn lưu được trên máy chủ.
/filemanager/UploadHandler.php
Bạn sửa code ở 2 nơi: line 1425 và line 490 của file đề cập trên (fix code 2 point, line 1425 and 490 as file above)
Dòng 1425 bạn thay đổi như sau (Line 1425 you can fix it as follows)
$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))){
$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));
}
Đổi thành (into)
$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));
}
Lỗi này sửa lỗi là thêm điều kiện khi tính data size của ảnh (more info: fix this error, you set condition in this event upload)
$uploaded_bytes = $this->fix_integer_overflow((int)$content_range[1]);
Đổi thành (change into)
if (isset($content_range[1])) {
$uploaded_bytes = $this->fix_integer_overflow((int)$content_range[1]);
} else {
$uploaded_bytes = 0;
}
Tại dòng 490 các bạn đổi dòng code như sau (and at line 490 you change code as below)
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);
}
$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;
}
Đổi thành (change into)
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);
}
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;
}
Thay đổi chỗ này thì thêm điều kiện trong dòng code điểm kiểm tra (more info: add more condition to check)
$uploaded_bytes = $this->fix_integer_overflow((int)$content_range[1]);
Đổi thành (change into)
if (isset($content_range[1])) {
$uploaded_bytes = $this->fix_integer_overflow((int)$content_range[1]);
}
And
if ($uploaded_bytes === $this->get_file_size($this->get_upload_path($name))) {
break;
}
Đổi thành (change into)
if (isset($uploaded_bytes)) {
if ($uploaded_bytes === $this->get_file_size($this->get_upload_path($name))) {
break;
}
}
Tested on my hosting and working ok
Thank for reading!