Restricting file type/extensions

Restricting file type/extensions

by Aylwin Cal -
Number of replies: 20

There is a patch available restricting the allowed file types for uploadhttp://tracker.moodle.org/browse/MDL-18713 

Does anyone know if this patch still works for versions 2.3.3+ and/or 2.4?

Also, does anyone know if there are any plans to include this as a built in feature for Moodle.  I would've thought something like this should be standard.

For example, I'd like to restrict the file type to .zip only.  This would ensure that the uploaded files are close to as small as possible to save disk space.

Average of ratings:Useful (1)
In reply to Aylwin Cal

Re: Restricting file type/extensions

by Minh-Tam Nguyen -

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:

mockup of file type restriction in assignment submission

 

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

  1. Create an assignment, set “restrict file types” to No
  2. Log in as a student
  3. Submit a .gif file
  4. File uploads successfully

Test 2

  1. Create an assignment, set “restrict file types” to Yes
  2. Select Word and PDF formats
  3. Log in as a student
  4. Upload a Word document
  5. File uploads successfully
  6. Upload a PDF document
  7. File uploads successfully
  8. Upload a gif file
  9. File will not upload

Test 3

  1. Create an assignment, set “restrict file types” to Yes
  2. Select Other format, de-select other formats
  3. Enter “txt” (without quotes)
  4. Save
  5. Validation error message is displayed and form does not save
  6. Change Other to be “*.txt” (without quotes)
  7. Save
  8. Form saves successfully
  9. Log in as student
  10. Upload .docx file
  11. File does not upload
  12. Upload .txt file
  13. File uploads successfully

Test 4

  1. Create an assignment, set “restrict file types” to Yes
  2. Select Other format, de-select other formats
  3. Enter “txt,java
  4. Save
  5. Validation error message is displayed and form does not save
  6. Change Other to be “*.txt;*.java”
  7. Save
  8. Validation error message is displayed and form does not save
  9. Change Other to be “*.txt,*.java”
  10. Save
  11. Form saves successfully
  12. Log in as student
  13. Upload .txt file
  14. File uploads successfully

Test 5

  1. Create an assignment, set “restrict file types” to Yes
  2. De-select all formats
  3. Save
  4. Validation error message is displayed and form does not save

 

(*) credit to Flinders University for writing the spec.
In reply to Minh-Tam Nguyen

Re: Restricting file type/extensions

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

I would suggest adding open doc formats from Open/LibreOffice to the list for word processed documents smile

Average of ratings:Useful (1)
In reply to Richard Oelmann

Re: Restricting file type/extensions

by Minh-Tam Nguyen -

I think it's a good suggestion, but I don't necessarily agree with adding odt to the same list as doc. 

One of the main use cases for this functionality is to ensure that the teacher is able to work with the files that the students are submitting. Sadly, MS Word 2011 on my Mac is unable to open odt files. MS Word 2010 on Windows on the other hand is able to open the files. So if a teacher only has access to MS Word for Mac, they wouldn't want to allow odf.

Similarly, I have seen several teachers completely stumped when receiving .rar files from students. This results in a support call to IT, to get the file opened or converted to zip.

How do others see this, especially people who work in tightly controlled COEs? 

In reply to Minh-Tam Nguyen

Re: Restricting file type/extensions

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

Well, its just a suggestion to use open formats and not restrict users to commercial proprietary offerings - and after all LibreOffice is a free download to use even on a Mac smile

Maybe a separate tick box for open formats so teachers can select to allow it or not, depending on what they have available

In reply to Minh-Tam Nguyen

Re: Restricting file type/extensions

by Dave Balch -

Good point - there are two to aspects to consider:

  1. Document type (document, image, video, etc.) - chosen according to the assignment.
  2. Document format (.odt, .jpg, .avi, etc.) - chosen according to which formats the staff can use.

I think the best approach to handle these would be to allow choice of document types in the assignment (like Minh-Tam Nguyen's mockup), and site-level (perhaps over-ridable at course-level?) customisation document format for each of the categories.

I would make the categories and possible formats as follows:

  • Document (*.pdf, *.doc, *.docx, *.odt, *.rtf, *.txt)
  • Spreadsheet (*.xls, *.xlsx, *.ods)
  • Presentation (*.ppt, .pptx, *.odp)
  • Image (*.gif, *.jpg, *.jpeg, *.png, *.svg, *.tiff, *.odg)
  • Video (*.mp4, *.flv, *.mov, *.avi)
  • Audio (*.mp3, *.ogg, *.wav, *.aac, *.wma, *.flac)
  • Database (*.accdb, *.odb)
  • Archive (*.zip, *.rar, *.gz, *.tgz)
  • Other (text box, type in comma-separated)

For a specific assignment, the document formats available in each document type would be limited to a subset of the list above (selected by the site or course admin).

In reply to Dave Balch

Re: Restricting file type/extensions

by Minh-Tam Nguyen -

Thanks Richard, Dave, Ken and Garry for your replies. 

I like Dave's suggested presets for document types within the assignment and a site-level setting to associate documents formates to document types. A default configuration as suggested by Dave would give ODF equal footing. If a particular institution has particularly tight COEs and want to be annoying, they could change it at the site level, yet teachers who want to provide their own list can still do so at the activity level using the "Other" field. 

I'm not yet convinced about the course-level override, because this would require an additional "Assignments in this course" settings group somewhere in the course edit page, creating additional clutter on an already very long and difficult to use form. Additionally, not all assignments in a course are going to require the same file type submissions, so teachers would still have to verify or modify the settings when creating new Assignment activities. In my eyes, for the moment, the benefit of saving time when creating the dropbox for "Essay 2" does not yet outweigh the clutter it woudl create in the Edit Course screen. (But this is why we're having this discussion.)

Thank you for mentioning Google Docs submission, Ken. Good point. 

Garry, I'm not sure I understand the difference between "restriction off" and "any file" in terms of how teachers will understand the usage of the feature. 

But thank you Garry for raising the fact that the restriction, if set, needs to be displayed to students. Very important.

 

 

In reply to Minh-Tam Nguyen

Re: Restricting file type/extensions

by Minh-Tam Nguyen -

Hi All, we'd like to start dev work on this shortly. 

As such, a summary of the changes to the original spec so far, as far as I can see, please correct me if I got something entirely wrong: 

We'l put in an admin setting to specify "Document Types" (Document, Spreadsheet, Presentation, Image, etc as suggested), with the default setup encouraging differen file types, ODF as much as closed formats, as suggested. 

Administrators can change if absolutely required in their institution. They will also be able to set the default for new assignemnts to not have a restriction, meaning if an instituton doesn't wan tot use it, they don't have to restrict types. 

And botht he expected document type and the allowed formats iwll be displayed to the students before they submit the file. 

Any further thoughts on this? 
Thanks, 
Minh-Tam

 

In reply to Minh-Tam Nguyen

Re: Restricting file type/extensions

by Jonathon Fowler -
Picture of Core developers Picture of Plugin developers

Hi folks

At my institution we've also identified a need for this feature, so I took a quick stab at implementing something based on the MDL-39913 Tracker issue's spec, but with a few refinements, to get us moving. Perhaps it can be useful as a basis for what is being proposed here, unless work has already begun on something that will be more likely to reach core. The code so far is in my Github repo and you can get a sense of how it differs from MDL-39913 by perusing this Google Doc. It adds to the core file submission plugin, but I may end up cloning the core plugin and adding these changes there to keep things separate and avoid interfering with the official codebase.

Cheers

Jonathon

In reply to Minh-Tam Nguyen

Re: Restricting file type/extensions

by Arshad Hussanee -

Hi Minh-Tam and all, 

We've been trialing this for the past few months and academics are loving the extra controls but there's still a few bugs to iron out. A main one experienced just a few days ago is a lecturer restricting to submit pdf only, students don't know how to convert word documents and simply change the extension from .docx to .pdf and Moodle will accept this submission. 

To make it even worst - now because the file extension doesn't match the document, our text matching system "Urkund" will not text match the document and come back with an error. 


I'm happy to provide more information if required,
Thanks

Shad

In reply to Minh-Tam Nguyen

Re: Restricting file type/extensions

by Ken Task -
Picture of Particularly helpful Moodlers

Have always thought education was a two way street.  Just because education is moving online hasn't changed that view.  When it comes to a students or teachers use of technology, then *all* need to raise their level of 'technical understanding'.  Hmmmm ... that usually is a side product of that two way street as teachers *can* learn from students - and there is nothing wrong with that - matter of fact, sharing knowledge of technical issues might actually improve student/teacher relations (the human side of online education).

Depends upon ones view ... and $ students have to spend on commercial products to be able to take a course.   Requiring certain document mimetypes does, in affect, make the course more expensive (to the student - hidden cost).  Wonder how many students decide NOT to take a course because of that added cost (if they knew about it in advance). Students will naturally, like all of us would (should), look for a free alternative (missing from the list ... Google Docs?).

Was a witness (and involved in 'solving an issue') to an event which ended up (in the middle of a semester) costing an ISD thousands of $ more for a video conferencing/duel credit course offered by a local junior college.  Prof sent a .docx to the facilitator that couldn't be opened because the facilitators computer didn't have the latest/greatest MS Office.  Prof refused to 'save as' but instead insisted he NOT change, but the ISD/class 'adjust'.  ISD had to purchase 16 copies of an upgrade to office to facilitate.  Had a domino affect in that the computers students were using also had to get an upgrade.  More $.

And why did that happen ... Prof wouldn't 'save as'!!!  'tightly controlled COE's' days are numbered ... period.

Just my two cents ...

'spirit of sharing', Ken

In reply to Minh-Tam Nguyen

Re: Restricting file type/extensions

by Garry Edmonds -

Hello Minh-Tam,

At the University of New England we already have this feature. We have been using it for a couple of years with success. The settings for ours are set at the same location on the assignment settings page, but rather than having an option to turn restrictions on or off we an option for ‘Any files’ as well PDF, etc.

Another feature not listed here is displaying the allowed file types to students. Rather than rely on teaching staff to manually add this to the assignment description the one we use adds another item to the submission status table, with the text “The following file types are allowed”.

Our plugin could do some minor work, so I am interested to see where this goes. I’m happy to talk further with you Minh-Tam about ours.

In reply to Garry Edmonds

Re: Restricting file type/extensions

by Garry Edmonds -

One thing I forgot to mention is that there is an option in the admin settings for the assignment module to set what the default allowable file type will be when a user creates a new assignment.

In reply to Garry Edmonds

Re: Restricting file type/extensions

by javier D -

hello
you have a guide on how to make the changes, I have moodle 3.

Thanks

In reply to Garry Edmonds

Re: Restricting file type/extensions

by John Lynch -

We're interested in developing our own version of this feature, which is slightly more restricted than Minh-Tam's version, and sounds more like yours, Gary. We have an instructor in Applied Linguistics who wants students to only be able to submit properly validated audio files in one type; right now, she regularly gets recordings in incorrect formats.

Would you be willing to share your code, or perhaps talk to our developer about how you did it?

In reply to John Lynch

Svar: Re: Restricting file type/extensions

by Alf Martin Johnsen -

Hi, we are interested in the code already created as well.

Perhaps we could check it out, rewrite if necessary,  and try to get it accepted as a part of the core?

Regards

Alf Martin

eFaktor, Norwegian and Danish Moodle Partner

In reply to Minh-Tam Nguyen

Re: Restricting file type/extensions

by Jez H -

I think something like this is needed more now PDF annotation / feedback is in core 2.6 as PDF annotation is useless unless students upload pdf assignments!

I understand why you have used check boxes but I think this is overly complex for most teachers and could probably be done with a single drop down / option list, perhaps allowing the drop down list contents to be configured via admin settings?

 

Average of ratings:Useful (1)
In reply to Minh-Tam Nguyen

Re: Restricting file type/extensions

by Mr. Marc -

has this been implemented into a plugin or a document that explains how to make the changes?

In reply to Minh-Tam Nguyen

Re: Restricting file type/extensions

by javier D -

hello,

you have a guide on how to make those changes , I have moodle 3 and want to try this function I need it , which files to modify to see those changes thanks

 


In reply to Aylwin Cal

Re: Restricting file type/extensions

by Shu Doi -

Hi,

We have created the file type restriction feature for Moodle 2.3 onwards.

Anyone interested please contact info@fishite.com

In reply to Shu Doi

Re: Restricting file type/extensions

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

So what exactly is your question/problem?  It is behaving as expected...