Skip to content

Commit

Permalink
MDL-24441, enforce course max file size
Browse files Browse the repository at this point in the history
  • Loading branch information
Dongsheng Cai committed Sep 29, 2010
1 parent b7b88c0 commit b8a6131
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 4 additions & 0 deletions mod/forum/post_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ function definition() {
$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);

Expand Down
2 changes: 1 addition & 1 deletion repository/repository_ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
// 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();
Expand Down
12 changes: 5 additions & 7 deletions repository/upload/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function print_login() {
* 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);
Expand Down Expand Up @@ -100,14 +100,12 @@ public function upload($saveas_filename) {
$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;
Expand Down

0 comments on commit b8a6131

Please sign in to comment.