Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Moodle Qtype Moopt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elc
Moodle Qtype Moopt
Commits
c91bf1d6
Commit
c91bf1d6
authored
1 year ago
by
Isabel Uffinger
Browse files
Options
Downloads
Patches
Plain Diff
check encoding of attached files and convert to utf-8
parent
073af36b
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
locallib.php
+4
-5
4 additions, 5 deletions
locallib.php
with
4 additions
and
5 deletions
locallib.php
+
4
−
5
View file @
c91bf1d6
...
@@ -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 is
t
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
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment