]> git.mjollnir.org Git - moodle.git/commitdiff
added new set_max_file_size method to moodleform MDL-6914
authorskodak <skodak>
Thu, 23 Nov 2006 08:24:58 +0000 (08:24 +0000)
committerskodak <skodak>
Thu, 23 Nov 2006 08:24:58 +0000 (08:24 +0000)
lib/formslib.php
mod/forum/post_form.php

index fe76daafa1b868ce0b9d182c450d2da7ec0b39bb..454c25e9d58c4e77971bf55990326bc05b6ce5e5 100644 (file)
@@ -224,6 +224,24 @@ class moodleform {
         $this->definition_after_data();
     }
 
+    /**
+     * Set maximum allowed uploaded file size.
+     * Must be used BEFORE creating of file element!
+     *
+     * @param object $course
+     * @param object $modbytes - max size limit defined in module 
+     */
+    function set_max_file_size($course=null, $modbytes=0) {
+        global $CFG, $COURSE;
+
+        if (empty($course->id)) {
+            $course = $COURSE;
+        }
+
+        $maxbytes = get_max_upload_file_size($CFG->maxbytes, $course->maxbytes, $modbytes);
+        $this->_form->setMaxFileSize($maxbytes);
+    }
+
     /**
      * Check that form was submitted. Does not check validity of submitted data.
      *
index 73334c2fe3f9d4ef5a0fc8bafec606e7ea3c68bb..1cfe754106aee51e55b8172d94c9f34c3b64869c 100644 (file)
@@ -19,10 +19,7 @@ class forum_post_form extends moodleform {
 
         // the upload manager is used directly in post precessing, moodleform::save_files() is not used yet
         $this->_upload_manager = new upload_manager('attachment', true, false, $course, false, $forum->maxbytes, true, true);
-
-        // set file max size to enable proper server side validation
-        $maxbytes = get_max_upload_file_size($CFG->maxbytes, $course->maxbytes, $forum->maxbytes);
-        $mform->setMaxFileSize($maxbytes);
+        $this->set_max_file_size($course, $forum->maxbytes);
 
         $mform->addElement('header', 'general', '');//fill in the data depending on page params
                                                     //later using set_defaults