MDL-24441, enforce course max file size
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user