Merge branch 'MDL-27919' of git://github.com/jamiepratt/moodle
[moodle.git] / repository / repository_ajax.php
index 6dc6247..ccf55cd 100644 (file)
@@ -205,6 +205,15 @@ switch ($action) {
             // method, so we use copy_to_area method
             // (local, user, coursefiles, recent)
             if ($repo->has_moodle_files()) {
+                // check filesize against max allowed size
+                $filesize = $repo->get_file_size($source);
+                if (empty($filesize)) {
+                    $err->error = get_string('filesizenull', 'repository');
+                    die(json_encode($err));
+                }
+                if (($maxbytes !== -1) && ($filesize > $maxbytes)) {
+                    throw new file_exception('maxbytes');
+                }
                 $fileinfo = $repo->copy_to_area($source, $itemid, $saveas_path, $saveas_filename);
                 if (!isset($fileinfo['event'])) {
                     $fileinfo['file'] = $fileinfo['title'];