MDL-42566 mod_data: introduced check to ensure the picture supplied is valid

This commit is contained in:
Mark Nelson 2013-10-31 16:06:42 +08:00
parent 68291f2d57
commit af9fc21cfd

View File

@ -250,6 +250,13 @@ class data_field_picture extends data_field_base {
$content->content = $draftfile->get_filename();
$file = $fs->create_file_from_storedfile($file_record, $draftfile);
// If the file is not a valid image, redirect back to the upload form.
if ($file->get_imageinfo() === false) {
$url = new moodle_url('/mod/data/edit.php', array('d' => $this->field->dataid));
redirect($url, get_string('invalidfiletype', 'error', $file->get_filename()));
}
$DB->update_record('data_content', $content);
$this->update_thumbnail($content, $file);