Time to resurrect this item.
We're planning to do some work together with our friends at Flinders University to allow teachers to restrict file types submitted by students.
The following is the proposed spec (*). I have created MDL-39913 "File type restrictions for Assignment submissions" to accompany this forum discussion.
Description:
When creating an assignment, teachers should have the option to restrict the types of files students may submit. When a student edits their submission, the filepicker should not allow files to be uploaded that do not match the specified filetypes.
The filetype options should be as follows:
- Word (*.doc, *.docx, *.rtf) - selected by default
- PDF (*.pdf) - selected by default
- Image (*.gif, *.jpg, *.jpeg, *.png), *.svg, *.tiff)
- Video (*.mp4, *.flv, *.mov, *.avi)
- Audio (*.mp3, *.ogg, *.wav, *.aac, *.wma)
- Other (text box, type in comma-separated)
The settings should be located within the “submission settings” area.
Note: it may be easier to use Moodle’s in-built file_get_typegroup function to retrieve sets of related extensions - for discussion.
Mockup:

Notes on settings:
- The “restrict file types” option should only be enabled if “file submissions” is on
- The file type options (Word, PDF, etc) should only be enabled if “restrict file types” is on
- Form validation should ensure the “other” value is in the correct format, eg *.extn (comma-separated list)
- Error message for "other" values: List should be in the format *.doc,*.docx
- Form validation should ensure that if “restrict file types” if set to “yes”, then at least one file type must be checked
- Help text should be as follows:
- If Restrict File Types is enabled, you can specify the file formats you will accept for this assignment. Students will not be able to upload files that are not in the format you select.
- If Restrict File Types is set to No, there will be no restriction on the type of files students may submit.
The filepicker element in the edit submission page should restrict the file types based on the assignment settings.
$mform->addElement('filepicker', 'userfile', get_string('file'), null,
array('maxbytes' => $maxbytes, 'accepted_types' => '[filetypes]'));
Test instructions:
Test 1
- Create an assignment, set “restrict file types” to No
- Log in as a student
- Submit a .gif file
- File uploads successfully
Test 2
- Create an assignment, set “restrict file types” to Yes
- Select Word and PDF formats
- Log in as a student
- Upload a Word document
- File uploads successfully
- Upload a PDF document
- File uploads successfully
- Upload a gif file
- File will not upload
Test 3
- Create an assignment, set “restrict file types” to Yes
- Select Other format, de-select other formats
- Enter “txt” (without quotes)
- Save
- Validation error message is displayed and form does not save
- Change Other to be “*.txt” (without quotes)
- Save
- Form saves successfully
- Log in as student
- Upload .docx file
- File does not upload
- Upload .txt file
- File uploads successfully
Test 4
- Create an assignment, set “restrict file types” to Yes
- Select Other format, de-select other formats
- Enter “txt,java”
- Save
- Validation error message is displayed and form does not save
- Change Other to be “*.txt;*.java”
- Save
- Validation error message is displayed and form does not save
- Change Other to be “*.txt,*.java”
- Save
- Form saves successfully
- Log in as student
- Upload .txt file
- File uploads successfully
Test 5
- Create an assignment, set “restrict file types” to Yes
- De-select all formats
- Save
- Validation error message is displayed and form does not save
(*) credit to Flinders University for writing the spec.