MDL-69257 core_h5p: Move $maxsize outside the foreach loop
authorMihail Geshoski <mihail@moodle.com>
Fri, 9 Oct 2020 02:23:28 +0000 (10:23 +0800)
committerMihail Geshoski <mihail@moodle.com>
Fri, 9 Oct 2020 02:36:01 +0000 (10:36 +0800)
There is no reason to repeatedly obtain the maximum size for uploading
files as a part of foreach loop.

h5p/ajax.php

index 5c55a5f..b5d7638 100644 (file)
@@ -78,10 +78,10 @@ switch ($action) {
         $token = required_param('token', PARAM_RAW);
         $contentid = required_param('contentId', PARAM_INT);
 
+        $maxsize = get_max_upload_file_size($CFG->maxbytes);
         // Check size of each uploaded file and scan for viruses.
         foreach ($_FILES as $uploadedfile) {
             $filename = clean_param($uploadedfile['name'], PARAM_FILE);
-            $maxsize = get_max_upload_file_size($CFG->maxbytes);
             if ($uploadedfile['size'] > $maxsize) {
                 H5PCore::ajaxError(get_string('maxbytesfile', 'error', ['file' => $filename, 'size' => display_size($maxsize)]));
                 return;