Selective upload manager in Moodle

Tags: php moodle
Question!

In Moodle 1.9.7, is it possible to somehow specify a white-list of the allowed extensions for the user uploaded files?



Answers

Looking at the source, there is no built in way to limit filetypes when modules use the upload_manager to process the uploaded files. There also is no use of any mimetype detection based on content of the files. The filelib libraries in moodle base their mimetype on file extension.

A neat way to do this for a module while is using the moodle upload manager object, would be to write a new class which extends the existing upload_manager class, and add some validatation based on file content.

Something like the following - you'll need to tidy this up a bit, and complete it with your own validation code.

class upload_manager_strict extends upload_manager {
  var $allowed_types
  function upload_manager_strict($inputname='', $deleteothers=false, $handlecollisions=false, $course=null, $recoverifmultiple=false, $modbytes=0, $silent=false, $allownull=false, $allownullmultiple=true, $allowed_types=null) {
    $this-


This video can help you solving your question :)
By: admin