From 5d7b52116cd95cdd3c041ec0f3fead0cda8a514e Mon Sep 17 00:00:00 2001 From: Isabel <isabel-andrea.uffinger@stud.hs-hannover.de> Date: Thu, 11 Apr 2024 14:43:44 +0200 Subject: [PATCH] added if(attached) --- locallib.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/locallib.php b/locallib.php index d33727d..1d2201b 100644 --- a/locallib.php +++ b/locallib.php @@ -296,18 +296,20 @@ function get_text_content_from_file($usercontext, $draftareaid, $keepfilename, $ //check if encoding of attached file is utf-8 else convert $content = $file->get_content(); - if($encoding!=null){ - $enc=$encoding; - } else { - $enc = mb_detect_encoding($content, null, true); - if($enc===false){ - throw new invalid_parameter_exception('Encoding of attached file ' . $filepath . $filename . ' could\'nt be detectet.'); + if($attached){ + if($encoding!=null){ + $enc=$encoding; + } else { + $enc = mb_detect_encoding($content, null, true); + if($enc===false){ + throw new invalid_parameter_exception('Encoding of attached file ' . $filepath . $filename . ' could\'nt be detectet.'); + } + } + if($enc!=='UTF-8'){ + $content = mb_convert_encoding($content, 'UTF-8', $enc); } } - if($enc!=='UTF-8'){ - $content = mb_convert_encoding($content, 'UTF-8', $enc); - } - + return $content; } -- GitLab