Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'MDL-26890-master' of git://github.com/ankitagarwal/moodle

  • Loading branch information...
commit c9f7b5e20ba1956e10a8397c9ac480009947a9bf 2 parents 48a7eed + c0d60b3
@nebgor nebgor authored
View
1  lang/en/repository.php
@@ -101,6 +101,7 @@
$string['filenotnull'] = 'You must select a file to upload.';
$string['filesaved'] = 'The file has been saved';
$string['filepicker'] = 'File picker';
+$string['filesizenull'] = 'File size cannot be determined';
$string['getfile'] = 'Select this file';
$string['hidden'] = 'Hidden';
$string['choosealink'] = 'Choose a link...';
View
25 repository/lib.php
@@ -1357,6 +1357,31 @@ public function get_file($url, $filename = '') {
}
/**
+ * Return size of a file in bytes.
+ *
+ * @param string $source encoded and serialized data of file
+ * @return integer file size in bytes
+ */
+ public function get_file_size($source) {
+ $browser = get_file_browser();
+ $params = unserialize(base64_decode($source));
+ $contextid = clean_param($params['contextid'], PARAM_INT);
+ $fileitemid = clean_param($params['itemid'], PARAM_INT);
+ $filename = clean_param($params['filename'], PARAM_FILE);
+ $filepath = clean_param($params['filepath'], PARAM_PATH);
+ $filearea = clean_param($params['filearea'], PARAM_SAFEDIR);
+ $component = clean_param($params['component'], PARAM_ALPHAEXT);
+ $context = get_context_instance_by_id($contextid);
+ $file_info = $browser->get_file_info($context, $component, $filearea, $fileitemid, $filepath, $filename);
+ if (!empty($file_info)) {
+ $filesize = $file_info->get_filesize();
+ } else {
+ $filesize = null;
+ }
+ return $filesize;
+ }
+
+ /**
* Return is the instance is visible
* (is the type visible ? is the context enable ?)
* @return boolean
View
9 repository/repository_ajax.php
@@ -205,6 +205,15 @@
// method, so we use copy_to_area method
// (local, user, coursefiles, recent)
if ($repo->has_moodle_files()) {
+ // check filesize against max allowed size
+ $filesize = $repo->get_file_size($source);
+ if (empty($filesize)) {
+ $err->error = get_string('filesizenull', 'repository');
+ die(json_encode($err));
+ }
+ if (($maxbytes !== -1) && ($filesize > $maxbytes)) {
+ throw new file_exception('maxbytes');
+ }
$fileinfo = $repo->copy_to_area($source, $itemid, $saveas_path, $saveas_filename);
echo json_encode($fileinfo);
die;
Please sign in to comment.
Something went wrong with that request. Please try again.