mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 13:02:07 +02:00
Merge branch 'MDL-26890-master' of git://github.com/ankitagarwal/moodle
This commit is contained in:
commit
c9f7b5e20b
@ -101,6 +101,7 @@ $string['filename'] = 'Filename';
|
||||
$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...';
|
||||
|
@ -1356,6 +1356,31 @@ abstract class repository {
|
||||
return array('path'=>$path, 'url'=>$url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ?)
|
||||
|
@ -205,6 +205,15 @@ switch ($action) {
|
||||
// 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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user