Learning Outcome
At the end of this post, you will know how to enable multiple file uploads to save on the amount of work (and mouse-clicks!) needed to upload N number of files in a link resource or assignment activity.
Necessity, (who) is the Mother of invention, said Plato.
Two days ago, I gave my Information Technology class an assignment where they had to upload nine Microsoft Word files within a week.
I had earlier enabled Moodle’s “Advanced uploading of files” assignment activity for that purpose. Here is one student’s response.

Simon, one of the more IT-savvy and inquisitive students, had posted a comment on my course page’s Whisper box. It caught my eye and I read these words:
Sir, can you make moodurian able to update more files at once? it’s a waste of time (sic) update file by file.
Waste of time? What waste of time? I replied that all one needs to do is to zip up your files, then upload that zipped file. A simple solution right? If it were that simple and convenient (which it isn’t), then how come none of my students had resorted to that little trick? Instead they obediently uploaded one file at a time like robots. Automatons.
Was Simon’s comment a plea for help and a clear sign of frustration?
I began to think about Simon’s brazen comment. I pondered. Then it dawned upon me that I was subjecting my students to mouse-click “hell”. Why? Because the “Advanced uploading of files” assignment activity only allows one file to be browsed, picked and uploaded at a time. Moodle 1.9 is good, no, great at many things, but this is NOT one of them. I then thought “Why NOT” change the file picker in Moodle 1.9? Why not, indeed!

I then decided to embark on a noble Quest to improve Moodle 1.9’s file picker. I searched moodle.org for information. I wanted to know how to select multiple-selected files from a dialog box. What? Pressing the Control key and left-clicking the mouse doesn’t select multiple files? Argh!
Okay, perhaps Moodle 2.2 doesn’t suffer from such an interface feature. I was wrong. In fact I became more frustrated because my Moodle 2.2 site’s file picker only allowed one file to be picked from my Windows XP Desktop. Bummer! (Note: I bet this problem will be a thing of the past with Moodle 2.3, 2.4, 2.5, etc.)

Professor Higgins, in the movie My Fair Lady, sighed and asked “Why can’t a woman be more like a man?”. Well, why can’t Moodle be more like Facebook?

Need another example?

Facebook has the multiple-file select dialog box when selecting images to be put into a photo album. Dropbox has the same thing to select more than one file at a time. So why not Moodle? Even as I type this, Moodle 2.3 is just around the corner and has features that are getting at least one person very, very excited. The file picker in Moodle 2.3 has been improved, and may even have that multiple-file select feature (I don’t know, I haven’t tried it out) that will render this post and my work obsolete.
After many hours over the last two days, I finally chanced upon two forum threads on Moodle.org that shed some light on my quest. Christian Kloimboeck’s post and Gustav W Delius’s post on Moodle.org proved to be promising.
After reading Gustav W Delius’ post, I knew that it was possible. C’mon, after all this is Computer Science, right? “England’s winning, anything’s possible!” (Flushed Away, 2007).
Diving in Christian’s post, I decided to get my finger tips dirty by actually doing some coding. After many hours, I am happy to report that I had managed to achieve something that might be useful for Moodle 1.9 administrators, teachers, students and users all over the world:

Just for fun, I also did this:

Christian Kloimboeck, I want to shake your hand and say “Thank you!” for your post on Moodle.org. Thanks to your ingenious code here, I managed to create something out of nothing.
Now then, where have we seen a file browser/picker like this before? Hmm…how about on Facebook? Yeah, that right! So if even Facebook has such an interface to upload files, then we can’t go wrong with modifying Moodle 1.9.15 to do the same right?

What about Dropbox, then?

So here’s what I achieved. I managed to allow the user to pick up to 10 files from the Desktop and then with a single click of the “Upload these files” button, upload all files direct into the assignment data folder. Not as good as Facebook’s or Dropbox’s multiple file picker in a single dialogue box, but definitely a time-saver.
Now, the moment of truth. I’m going to let you in on the secret. I’m going to tell you how I did it in two parts. In Part I, I will explain in detail how I enabled my Moodle 1.9 site to allow multiple file uploads in a ‘Link to a file or website’ resource. In Part II, I show you how I enabled uploading of multiple files in an assignment. Specifically, the ‘Advanced uploading of files’ assignment activity.
Now let’s get going. The game’s afoot, Watson!
Part I: Enabling dual file uploads in a ‘Link to a file or website” resource
To save you tears and to make this as painless as I possibly can, I will simplify the learning by showing you how to enable two file uploads instead of 10 file uploads. Once you see how easy it is, you can easily expand the code yourself to enable up to 4, 6 or even 10 number of uploads.
Oh don’t worry, right at the bottom of this post lies the download links to the modified php files that allow you to achieve the same results as I. You might want to go there right now because the next few Page Downs will probably give you a headache or that sinking feeling that “it’s too complicated and I don’t have time to wade through all this geeky stuff!”.
Your choice.
Okay, so still with me? Let’s be brave and proceed with the surgery, erm, I mean the code modification, shall we? This will only hurt just a little bit.
Edit /moodle or public html/files/index.php
Insert code shown in the gray background inside the images shown. The same code is reproduced for your copy-and-paste convenience, at the bottom of each image.
You can refer to the line numbers shown to know the exact location of the code to be inserted. You might also want to make use of the Ctrl-F (Find text) feature of your web browser.
- $um1 = new upload_manager(‘userfile1’,false,false,$course,false,0);if ($um1->process_file_uploads($dir)) { notify(get_string(‘uploadedfile’)); }
- upload_print_form_fragment(1,array(‘userfile1’),null,false,null,$upload_max_filesize,0,false);
If good English grammar matters to you, then edit /moodle or public_html/lang/en_utf8/moodle.php
Line 1590:
$string[‘uploadafile’] = ‘Upload a file’;
change to
$string[‘uploadafile’] = ‘Upload one or more files‘;

Like to maintain consistently good and correct English grammar on your Moodle site? Then edit /moodle or public_html/lang/en_utf8/moodle.php (the same file!)
Line 1609:
$string[‘uploadthisfile’] = ‘Upload a file’;
change to
$string[‘uploadthisfile’] = ‘Upload these files‘;

So far so good….now for the acid test.

Igor!!! Pull the SWITCH!!!
Yes, Master.

You are alive! I created you! Muahahahahahaha.
End of Part I.
At this point in this blog post, you just might want to brew some char and sit down in a nice comfortable chair because this is where it gets….complicated.
Part II: Enabling multiple file uploads in an ‘Advanced Uploading Of Files” assignment activity
Once again, I will simplify the learning process by showing you how to enable two file uploads instead of ten file uploads. Once you see how easy it is, you can easily expand the code yourself to enable up to N number of uploads. Really! Trust me.
Edit /moodle or public_html/mod/assignment/type/upload/assignment.class.php
As usual, insert the code shown in the gray background.

Tip: If you find these images too small to read, then in Firefox, right-click on an image and select the “View Image” option. An enlarged image will appear in a new Firefox browser tab.


- $um1 = new upload_manager(‘newfile1’,false,true,$this->course,false,$this->assignment->maxbytes,true);

to the above section is too large to fit inside this caption. So I have reproduced it below:
LOL! Just found out about Guy Thomas’ “Enhanced File Module (multiple uploads)” resource type for Moodle 1.9.
http://www.citricity.com/moodlegpl/enhanced_file_mod/
and
http://moodle.org/mod/data/view.php?d=13&rid=3546&filter=1
which has multiple select and works very well.