mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 13:38:32 +01:00
MDL-53577 repository: Added maxbytes error message
Changing the error message that is displayed to users when they upload a file that is greater than the maximum upload size. Does not include all upload cases; focuses on those most used by students.
This commit is contained in:
parent
fed66ad9e2
commit
a2fb838e82
@ -28,3 +28,5 @@ tagtype,core_tag
|
||||
manageofficialtags,core_tag
|
||||
settypeofficial,core_tag
|
||||
filetoolarge,core
|
||||
maxbytesforfile,core
|
||||
maxbytes,core_error
|
||||
|
@ -368,7 +368,7 @@ $string['listupdatefail'] = 'DB operation failed when editing list hierarchy';
|
||||
$string['logfilenotavailable'] = 'Logs not available';
|
||||
$string['loginasnoenrol'] = 'You cannot use enrol or unenrol when in course "Login as" session';
|
||||
$string['loginasonecourse'] = 'You cannot enter this course.<br /> You have to terminate the "Login as" session before entering any other course.';
|
||||
$string['maxbytes'] = 'The file is larger than the maximum size allowed.';
|
||||
$string['maxbytesfile'] = 'The file {$a->file} is too large. The maximum size you can upload is {$a->size}.';
|
||||
$string['maxareabytes'] = 'The file is larger than the space remaining in this area.';
|
||||
$string['messagingdisable'] = 'Messaging is disabled on this site';
|
||||
$string['mimetexisnotexist'] = 'Your system is not configured to run mimeTeX. You need to download the appropriate executable for you PHP_OS platform from <a href="http://moodle.org/download/mimetex/">http://moodle.org/download/mimetex/</a>, or obtain the C source from <a href="http://www.forkosh.com/mimetex.zip"> http://www.forkosh.com/mimetex.zip</a>, compile it and put the executable into your moodle/filter/tex/ directory.';
|
||||
@ -578,3 +578,6 @@ $string['xmldberror'] = 'XMLDB error!';
|
||||
$string['alreadyloggedin'] = 'You are already logged in as {$a}, you need to log out before logging in as different user.';
|
||||
$string['youcannotdeletecategory'] = 'You cannot delete category \'{$a}\' because you can neither delete the contents, nor move them elsewhere.';
|
||||
$string['protected_cc_not_supported'] = 'Protected cartridges not supported.';
|
||||
|
||||
// Deprecated since Moodle 3.1.
|
||||
$string['maxbytes'] = 'The file is larger than the maximum size allowed.';
|
||||
|
@ -1096,7 +1096,6 @@ $string['markedthistopic'] = 'This topic is highlighted as the current topic';
|
||||
$string['markthistopic'] = 'Highlight this topic as the current topic';
|
||||
$string['matchingsearchandrole'] = 'Matching \'{$a->search}\' and {$a->role}';
|
||||
$string['maxareabytesreached'] = 'The file (or the total size of several files) is larger than the space remaining in this area.';
|
||||
$string['maxbytesforfile'] = 'The file {$a} is larger than the maximum size allowed.';
|
||||
$string['maxfilesize'] = 'Maximum size for new files: {$a}';
|
||||
$string['maxfilesreached'] = 'You are allowed to attach a maximum of {$a} file(s) to this item';
|
||||
$string['maximumchars'] = 'Maximum of {$a} characters';
|
||||
@ -2030,3 +2029,4 @@ $string['zippingbackup'] = 'Zipping backup';
|
||||
|
||||
// Deprecated since Moodle 3.1.
|
||||
$string['filetoolarge'] = 'is too large to upload';
|
||||
$string['maxbytesforfile'] = 'The file {$a} is larger than the maximum size allowed.';
|
||||
|
@ -589,7 +589,11 @@ M.form_dndupload.init = function(Y, options) {
|
||||
for (i=0; i<files.length; i++) {
|
||||
if (this.options.maxbytes > 0 && files[i].size > this.options.maxbytes) {
|
||||
// Check filesize before attempting to upload.
|
||||
this.print_msg(M.util.get_string('maxbytesforfile', 'moodle', files[i].name), 'error');
|
||||
var maxbytesdisplay = this.display_size(this.options.maxbytes);
|
||||
this.print_msg(M.util.get_string('maxbytesfile', 'error', {
|
||||
file: files[i].name,
|
||||
size: maxbytesdisplay
|
||||
}), 'error');
|
||||
this.uploadqueue = []; // No uploads if one file is too big.
|
||||
return;
|
||||
}
|
||||
@ -606,6 +610,31 @@ M.form_dndupload.init = function(Y, options) {
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Generate the display for file size
|
||||
* @param int size The size to convert to human readable form
|
||||
* @return string
|
||||
*/
|
||||
display_size: function(size) {
|
||||
// This is snippet of code (with some changes) is from the display_size function in moodlelib.
|
||||
var gb = M.util.get_string('sizegb'),
|
||||
mb = M.util.get_string('sizemb'),
|
||||
kb = M.util.get_string('sizekb'),
|
||||
b = M.util.get_string('sizeb');
|
||||
|
||||
if (size >= 1073741824) {
|
||||
size = Math.round(size / 1073741824 * 10) / 10 + gb;
|
||||
} else if (size >= 1048576) {
|
||||
size = Math.round(size / 1048576 * 10) / 10 + mb;
|
||||
} else if (size >= 1024) {
|
||||
size = Math.round(size / 1024 * 10) / 10 + kb;
|
||||
} else {
|
||||
size = parseInt(size, 10) + ' ' + b;
|
||||
}
|
||||
|
||||
return size;
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a single file to the uploadqueue, whilst checking the maxfiles limit
|
||||
* @param File file - the file to add
|
||||
|
@ -785,7 +785,8 @@ class page_requirements_manager {
|
||||
'fullpath' => '/lib/form/dndupload.js',
|
||||
'requires' => array('node', 'event', 'json', 'core_filepicker'),
|
||||
'strings' => array(array('uploadformlimit', 'moodle'), array('droptoupload', 'moodle'), array('maxfilesreached', 'moodle'),
|
||||
array('dndenabled_inbox', 'moodle'), array('fileexists', 'moodle'), array('maxbytesforfile', 'moodle'),
|
||||
array('dndenabled_inbox', 'moodle'), array('fileexists', 'moodle'), array('maxbytesfile', 'error'),
|
||||
array('sizegb', 'moodle'), array('sizemb', 'moodle'), array('sizekb', 'moodle'), array('sizeb', 'moodle'),
|
||||
array('maxareabytesreached', 'moodle'), array('serverconnection', 'error'),
|
||||
));
|
||||
break;
|
||||
|
@ -888,7 +888,9 @@ abstract class repository implements cacheable_object {
|
||||
// the file needs to copied to draft area
|
||||
$stored_file = self::get_moodle_file($source);
|
||||
if ($maxbytes != -1 && $stored_file->get_filesize() > $maxbytes) {
|
||||
throw new file_exception('maxbytes');
|
||||
$maxbytesdisplay = display_size($maxbytes);
|
||||
throw new file_exception('maxbytesfile', (object) array('file' => $filerecord['filename'],
|
||||
'size' => $maxbytesdisplay));
|
||||
}
|
||||
// Validate the size of the draft area.
|
||||
if (file_is_draft_area_limit_reached($draftitemid, $areamaxbytes, $stored_file->get_filesize())) {
|
||||
@ -1699,13 +1701,17 @@ abstract class repository implements cacheable_object {
|
||||
// files that are references to local files are already in moodle filepool
|
||||
// just validate the size
|
||||
if ($maxbytes > 0 && $file->get_filesize() > $maxbytes) {
|
||||
throw new file_exception('maxbytes');
|
||||
$maxbytesdisplay = display_size($maxbytes);
|
||||
throw new file_exception('maxbytesfile', (object) array('file' => $file->get_filename(),
|
||||
'size' => $maxbytesdisplay));
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
if ($maxbytes > 0 && $file->get_filesize() > $maxbytes) {
|
||||
// note that stored_file::get_filesize() also calls synchronisation
|
||||
throw new file_exception('maxbytes');
|
||||
$maxbytesdisplay = display_size($maxbytes);
|
||||
throw new file_exception('maxbytesfile', (object) array('file' => $file->get_filename(),
|
||||
'size' => $maxbytesdisplay));
|
||||
}
|
||||
$fs = get_file_storage();
|
||||
$contentexists = $fs->content_exists($file->get_contenthash());
|
||||
|
@ -283,7 +283,9 @@ switch ($action) {
|
||||
|
||||
// Check if exceed maxbytes.
|
||||
if ($maxbytes != -1 && filesize($downloadedfile['path']) > $maxbytes) {
|
||||
throw new file_exception('maxbytes');
|
||||
$maxbytesdisplay = display_size($maxbytes);
|
||||
throw new file_exception('maxbytesfile', (object) array('file' => $record->filename,
|
||||
'size' => $maxbytesdisplay));
|
||||
}
|
||||
|
||||
// Check if we exceed the max bytes of the area.
|
||||
|
@ -191,7 +191,9 @@ class repository_upload extends repository {
|
||||
}
|
||||
|
||||
if (($maxbytes!==-1) && (filesize($_FILES[$elname]['tmp_name']) > $maxbytes)) {
|
||||
throw new file_exception('maxbytesforfile', $_FILES[$elname]['name']);
|
||||
$maxbytesdisplay = display_size($maxbytes);
|
||||
throw new file_exception('maxbytesfile', (object) array('file' => $record->filename,
|
||||
'size' => $maxbytesdisplay));
|
||||
}
|
||||
|
||||
if (file_is_draft_area_limit_reached($record->itemid, $areamaxbytes, filesize($_FILES[$elname]['tmp_name']))) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user