Skip to content
Snippets Groups Projects
Commit c91bf1d6 authored by Isabel Uffinger's avatar Isabel Uffinger
Browse files

check encoding of attached files and convert to utf-8

parent 073af36b
Branches
No related tags found
No related merge requests found
...@@ -294,17 +294,16 @@ function get_text_content_from_file($usercontext, $draftareaid, $keepfilename, $ ...@@ -294,17 +294,16 @@ function get_text_content_from_file($usercontext, $draftareaid, $keepfilename, $
// TODO: make sure the mimetype is plain text // TODO: make sure the mimetype is plain text
// even task.xmls may contain mistakes (eg PDF ) // even task.xmls may contain mistakes (eg PDF )
//check if encoding of attached ist utf-8 else convert //check if encoding of attached file is utf-8 else convert
$content = $file->get_content(); $content = $file->get_content();
if($encoding!==false){ if($encoding!=null){
$enc=$encoding; $enc=$encoding;
} else { } else {
$enc = mb_detect_encoding($content, mb_detect_order(), true); $enc = mb_detect_encoding($content, null, true);
if($enc===false){ if($enc===false){
throw new invalid_parameter_exception('Encoding of attached file ' . $filepath . $filename . 'could\'nt be detectet.'); throw new invalid_parameter_exception('Encoding of attached file ' . $filepath . $filename . 'could\'nt be detectet.');
} }
} }
$content = mb_convert_encoding($content, $enc, 'UTF-8');
if($enc!=='UTF-8'){ if($enc!=='UTF-8'){
$content = mb_convert_encoding($content, 'UTF-8', $enc); $content = mb_convert_encoding($content, 'UTF-8', $enc);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment