Skip to content

Commit c4f93c5

Browse files
committed
Fix handling of file uploads
- allow upload of one file only. - new submit does not load previously existing files.
1 parent 604bf5c commit c4f93c5

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

classes/question/file.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ protected function question_survey_display($formdata, $descendantsdata, $blankqu
8282
$draftitemid = file_get_submitted_draft_itemid($elname);
8383
$component = 'mod_questionnaire';
8484
$options = $this->get_file_manager_option();
85-
file_prepare_draft_area($draftitemid, $this->context->id, $component, 'file', $this->id, $options);
85+
if ($draftitemid > 0) {
86+
file_prepare_draft_area($draftitemid, $this->context->id, $component, 'file', $this->id, $options);
87+
} else {
88+
$draftitemid = file_get_unused_draft_itemid();
89+
}
8690
// Filemanager form element implementation is far from optimal, we need to rework this if we ever fix it...
8791
require_once("$CFG->dirroot/lib/form/filemanager.php");
8892

classes/responsetype/file.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ public static function answers_from_webform($responsedata, $question) {
4848
$files = $fs->get_area_files($question->context->id, 'mod_questionnaire', 'file', $question->id,
4949
"itemid, filepath, filename",
5050
false);
51-
$file = reset($files);
52-
$record->value = $file->get_id();
53-
$answers[] = answer\answer::create_from_data($record);
51+
if (!empty($files)) {
52+
$file = reset($files);
53+
$record->value = $file->get_id();
54+
$answers[] = answer\answer::create_from_data($record);
55+
}
5456
}
5557
return $answers;
5658
}

0 commit comments

Comments
 (0)