MDL-33445 Added file size check to files inserted by reference

This commit is contained in:
Marina Glancy 2012-05-31 12:59:43 +08:00
parent 2dfa16ef8a
commit 9945ec5e13

View File

@ -254,21 +254,24 @@ switch ($action) {
$event['existingfile']->filepath = $saveas_path;
$event['existingfile']->filename = $saveas_filename;
$event['existingfile']->url = moodle_url::make_draftfile_url($itemid, $saveas_path, $saveas_filename)->out();;
echo json_encode($event);
die;
} else {
$storedfile = $fs->create_file_from_reference($record, $repo_id, $reference);
$event = array(
'url'=>moodle_url::make_draftfile_url($storedfile->get_itemid(), $storedfile->get_filepath(), $storedfile->get_filename())->out(),
'id'=>$storedfile->get_itemid(),
'file'=>$storedfile->get_filename(),
'icon' => $OUTPUT->pix_url(file_file_icon($storedfile, 32))->out(),
);
}
if ($maxbytes !== -1 && $storedfile->get_filesize() > $maxbytes) {
$storedfile->delete();
throw new file_exception('maxbytes');
}
$storedfile = $fs->create_file_from_reference($record, $repo_id, $reference);
// Repository plugin callback
// You can cache reository file in this callback
// or complete other tasks.
$repo->cache_file_by_reference($reference, $storedfile);
$info = array(
'url'=>moodle_url::make_draftfile_url($storedfile->get_itemid(), $storedfile->get_filepath(), $storedfile->get_filename())->out(),
'id'=>$storedfile->get_itemid(),
'file'=>$storedfile->get_filename(),
'icon' => $OUTPUT->pix_url(file_file_icon($storedfile, 32))->out(),
);
echo json_encode($info);
echo json_encode($event);
die;
} else if ($repo->has_moodle_files()) {
// Some repository plugins (local, user, coursefiles, recent) are hosting moodle