Multiple file upload in Moodle?

Re: Multiple file upload in Moodle?

by Christian Kloimboeck -
Number of replies: 0
Dear Andrew,

to upload more than one file especially from different local directories without zipping them before I added/copied some lines in the php script moodle/files/index.php in the upload section.
Here is an example (look at userfile1 and $um1) to upload two files at once. Actually I use one where 8 files can be uploaded at once.

if ($save and confirm_sesskey()) {
$course->maxbytes = 0; // We are ignoring course limits
$um = new upload_manager('userfile',false,false,$course,false,0);
$um1 = new upload_manager('userfile1',false,false,$course,false,0);
$dir = "$basedir$wdir";
if ($um->process_file_uploads($dir)) {
notify(get_string('uploadedfile'));
}
if ($um1->process_file_uploads($dir)) {
notify(get_string('uploadedfile'));
}
// um will take care of error reporting.
displaydir($wdir);
} else {
$upload_max_filesize = get_max_upload_file_size($CFG->maxbytes);
$filesize = display_size($upload_max_filesize);

$struploadafile = get_string("uploadafile");
$struploadthisfile = get_string("uploadthisfile");
$strmaxsize = get_string("maxsize", "", $filesize);
$strcancel = get_string("cancel");

echo "<p>$struploadafile ($strmaxsize) --> <b>$wdir</b></p>";
echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"index.php\">";
echo "<div>";
echo "<table><tr><td colspan=\"2\">";
echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
echo " <input type=\"hidden\" name=\"action\" value=\"upload\" />";
echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
upload_print_form_fragment(1,array('userfile'),null,false,null,$upload_max_filesize,0,false);
upload_print_form_fragment(1,array('userfile1'),null,false,null,$upload_max_filesize,0,false);

echo " </td></tr></table>";

I am sure, that this simple hack is not a very nice solution, but it works from moodle1.5* up to moodle1.9*.

wmbw
Christian