TinyMCEに画像アップロード機能「RESPONSIVE filemanager」を入れていたのですが、PHPのバージョンを8.0に上げたところ色々とエラーが出るようになってしまいました。
ファイルマネージャー
画像の挿入・編集モーダルの中、右側のアイコンをクリックしてファイルマネージャを確認しようとすると
Fatal error: Uncaught ValueError: mb_http_input(): Argument #1 ($type) must be one of "G", "P", "C", "S", "I", or "L" in
とかなんとか言われるのでファイルを修正していきます。
/filemanager/config/config.phpの9行目あたり、
mb_http_input('UTF-8'); →mb_http_input() に置き換えます。
サムネイル
先程のエラーは出なくなったのですが、サムネイルがうまく表示されていませんでした。仕方がないのでこれも修正します。
/filemanager/include/php_image_magician.phpの2791行目あたり
if ( ! is_resource($this->imageResized))
を
if ( ! is_resource($this->imageResized) && !($this->imageResized instanceof \GdImage))
に書き換えます。
アップロード画面
今度はファイルをアップロードしようとするとエラーがでました。
「Add file」後に「Start upload」を押すと、アップロード自体は成功するものの
SyntaxError: Unexpected token '<', "<br /> <b>"... is not valid JSON
と怒られました。
/filemanager/UploadHandler.phpを2箇所ほど書き換えます。
まずは、490行目辺り
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:
$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;
}
を
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;
}
に。
続いて1425行目辺り
$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));
}
を
$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));
}
に修正します。
これでひとまず動くようになりました。とりあえず良しとしましょう。