From c80a13c7368feacadf700961f6532991a5d16052 Mon Sep 17 00:00:00 2001 From: skodak Date: Thu, 23 Nov 2006 08:24:58 +0000 Subject: [PATCH] added new set_max_file_size method to moodleform MDL-6914 --- lib/formslib.php | 18 ++++++++++++++++++ mod/forum/post_form.php | 5 +---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/formslib.php b/lib/formslib.php index fe76daafa1..454c25e9d5 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -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. * diff --git a/mod/forum/post_form.php b/mod/forum/post_form.php index 73334c2fe3..1cfe754106 100644 --- a/mod/forum/post_form.php +++ b/mod/forum/post_form.php @@ -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 -- 2.39.5