From b8a6131b945ba153868f99d9a33cf75432b9cb4e Mon Sep 17 00:00:00 2001 From: Dongsheng Cai Date: Wed, 29 Sep 2010 10:13:35 +0000 Subject: [PATCH] MDL-24441, enforce course max file size --- mod/forum/post_form.php | 4 ++++ repository/repository_ajax.php | 2 +- repository/upload/lib.php | 12 +++++------- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/mod/forum/post_form.php b/mod/forum/post_form.php index a85a73cce63..b26deafc561 100644 --- a/mod/forum/post_form.php +++ b/mod/forum/post_form.php @@ -40,6 +40,10 @@ class mod_forum_post_form extends moodleform { $modcontext = $this->_customdata['modcontext']; $forum = $this->_customdata['forum']; $post = $this->_customdata['post']; + // if $forum->maxbytes == '0' means we should use $course->maxbytes + if ($forum->maxbytes == '0') { + $forum->maxbytes = $course->maxbytes; + } // TODO: add max files and max size support $editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'trusttext'=>true, 'context'=>$modcontext); diff --git a/repository/repository_ajax.php b/repository/repository_ajax.php index b51d121ec2f..6ff644a1fc1 100755 --- a/repository/repository_ajax.php +++ b/repository/repository_ajax.php @@ -251,7 +251,7 @@ switch ($action) { // see MDL-23407 try { // TODO: add file scanning MDL-19380 into each plugin - $result = $repo->upload($saveas_filename); + $result = $repo->upload($saveas_filename, $maxbytes); echo json_encode($result); } catch (Exception $e) { $err->error = $e->getMessage(); diff --git a/repository/upload/lib.php b/repository/upload/lib.php index 85e21370631..ef682d71588 100755 --- a/repository/upload/lib.php +++ b/repository/upload/lib.php @@ -41,7 +41,7 @@ class repository_upload extends repository { * Process uploaded file * @return array|bool */ - public function upload($saveas_filename) { + public function upload($saveas_filename, $maxbytes) { global $USER, $CFG; $types = optional_param('accepted_types', '*', PARAM_RAW); @@ -100,14 +100,12 @@ class repository_upload extends repository { $record->itemid = 0; } + if (($maxbytes!==-1) && (filesize($_FILES[$elname]['tmp_name']) > $maxbytes)) { + throw new file_exception('maxbytes'); + } + if ($file = $fs->get_file($context->id, $record->component, $record->filearea, $record->itemid, $record->filepath, $record->filename)) { throw new moodle_exception('fileexists', 'repository'); - //$record->filename = ; - //return array( - //'url'=>moodle_url::make_draftfile_url($file->get_itemid(), $file->get_filepath(), $file->get_filename())->out(), - //'id'=>$file->get_itemid(), - //'file'=>$file->get_filename() - //); } $record->contextid = $context->id;