Skip to content
Snippets Groups Projects
Unverified Commit 64e6caaa authored by Svein-Tore Griff With's avatar Svein-Tore Griff With Committed by GitHub
Browse files

Merge pull request #475 from davidherney/issue-200

Check max upload file size and use antivirus if apply
parents c0627146 05dc02f9
Branches
No related tags found
No related merge requests found
...@@ -380,6 +380,8 @@ class file_storage implements \H5PFileStorage { ...@@ -380,6 +380,8 @@ class file_storage implements \H5PFileStorage {
*/ */
// @codingStandardsIgnoreLine // @codingStandardsIgnoreLine
public function saveFile($file, $contentid, $contextid = null) { public function saveFile($file, $contentid, $contextid = null) {
global $CFG;
if ($contentid !== 0) { if ($contentid !== 0) {
// Grab cm context. // Grab cm context.
$cm = \get_coursemodule_from_instance('hvp', $contentid); $cm = \get_coursemodule_from_instance('hvp', $contentid);
...@@ -388,6 +390,26 @@ class file_storage implements \H5PFileStorage { ...@@ -388,6 +390,26 @@ class file_storage implements \H5PFileStorage {
} else if ($contextid === null) { } else if ($contextid === null) {
// Check for context id in params. // Check for context id in params.
$contextid = optional_param('contextId', null, PARAM_INT); $contextid = optional_param('contextId', null, PARAM_INT);
$context = \context::instance_by_id($contextid);
}
if (!$context) {
\H5PCore::ajaxError(get_string('invalidcontext', 'error'));
return;
}
$maxsize = get_max_upload_file_size($CFG->maxbytes);
// Check size of each uploaded file and scan for viruses.
foreach ($_FILES as $uploadedfile) {
$filename = clean_param($uploadedfile['name'], PARAM_FILE);
if (!has_capability('moodle/course:ignorefilesizelimits', $context)) {
if ($uploadedfile['size'] > $maxsize) {
\H5PCore::ajaxError(get_string('maxbytesfile', 'error', ['file' => $filename, 'size' => display_size($maxsize)]));
return;
}
}
\core\antivirus\manager::scan_file($uploadedfile['tmp_name'], $filename, true);
} }
// Files not yet related to any activities are stored in a course context // Files not yet related to any activities are stored in a course context
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment