diff --git a/locallib.php b/locallib.php
index 4a1df0d2cf4cfb395411ca411d39d3406011b749..7d6ea832954c7b149fa70e3698caa3ca069e4859 100644
--- a/locallib.php
+++ b/locallib.php
@@ -294,19 +294,18 @@ function get_text_content_from_file($usercontext, $draftareaid, $keepfilename, $
     // TODO: make sure the mimetype is plain text
     // 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();
-    if($encoding!==false){
+    if($encoding!=null){
         $enc=$encoding;
     } else {
-        $enc = mb_detect_encoding($content, mb_detect_order(), true);
+        $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.');
         }
     }
-    $content = mb_convert_encoding($content, $enc, 'UTF-8');
     if($enc!=='UTF-8'){
-        $content = mb_convert_encoding($content, 'UTF-8', $enc);
+        $content = mb_convert_encoding($content, 'UTF-8', $enc);        
     }
 
     return $content;