mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
"MDL-23268, remove file_browser, urldecode, clean filename, fixed fie overriding issue"
This commit is contained in:
parent
6c5b99d9f7
commit
64654e78b6
2 changed files with 21 additions and 7 deletions
|
@ -109,6 +109,22 @@ M.core_filepicker.init = function(Y, options) {
|
||||||
params[i] = args['params'][i];
|
params[i] = args['params'][i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (args.action == 'upload') {
|
||||||
|
var list = [];
|
||||||
|
for(var k in params) {
|
||||||
|
var value = params[k];
|
||||||
|
if(value instanceof Array) {
|
||||||
|
for(var i in value) {
|
||||||
|
list.push(k+'[]='+value[i]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
list.push(k+'='+value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
params = list.join('&');
|
||||||
|
} else {
|
||||||
|
params = build_querystring(params);
|
||||||
|
}
|
||||||
var cfg = {
|
var cfg = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
on: {
|
on: {
|
||||||
|
@ -145,7 +161,7 @@ M.core_filepicker.init = function(Y, options) {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
|
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
|
||||||
},
|
},
|
||||||
data: build_querystring(params),
|
data: params,
|
||||||
context: this
|
context: this
|
||||||
};
|
};
|
||||||
if (args.form) {
|
if (args.form) {
|
||||||
|
|
|
@ -56,7 +56,7 @@ class repository_upload extends repository {
|
||||||
$record = new stdclass;
|
$record = new stdclass;
|
||||||
$record->filearea = 'draft';
|
$record->filearea = 'draft';
|
||||||
$record->component = 'user';
|
$record->component = 'user';
|
||||||
$record->filepath = urldecode(optional_param('savepath', '/', PARAM_PATH));
|
$record->filepath = optional_param('savepath', '/', PARAM_PATH);
|
||||||
$record->itemid = optional_param('itemid', 0, PARAM_INT);
|
$record->itemid = optional_param('itemid', 0, PARAM_INT);
|
||||||
$record->license = optional_param('license', $CFG->sitedefaultlicense, PARAM_TEXT);
|
$record->license = optional_param('license', $CFG->sitedefaultlicense, PARAM_TEXT);
|
||||||
$record->author = optional_param('author', '', PARAM_TEXT);
|
$record->author = optional_param('author', '', PARAM_TEXT);
|
||||||
|
@ -65,7 +65,6 @@ class repository_upload extends repository {
|
||||||
$elname = 'repo_upload_file';
|
$elname = 'repo_upload_file';
|
||||||
|
|
||||||
$fs = get_file_storage();
|
$fs = get_file_storage();
|
||||||
$browser = get_file_browser();
|
|
||||||
$sm = get_string_manager();
|
$sm = get_string_manager();
|
||||||
|
|
||||||
if ($record->filepath !== '/') {
|
if ($record->filepath !== '/') {
|
||||||
|
@ -81,7 +80,7 @@ class repository_upload extends repository {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($record->filename)) {
|
if (empty($record->filename)) {
|
||||||
$record->filename = $_FILES[$elname]['name'];
|
$record->filename = clean_param($_FILES[$elname]['name'], PARAM_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->mimetypes != '*') {
|
if ($this->mimetypes != '*') {
|
||||||
|
@ -104,9 +103,8 @@ class repository_upload extends repository {
|
||||||
$record->itemid = 0;
|
$record->itemid = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($file = $browser->get_file_info($context, $record->filearea, $record->itemid, $record->filepath, $record->filename)) {
|
if ($file = $fs->get_file($context->id, $record->component, $record->filearea, $record->itemid, $record->filepath, $record->filename)) {
|
||||||
$file->delete();
|
throw new moodle_exception('fileexist');
|
||||||
//throw new moodle_exception('fileexist');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$record->contextid = $context->id;
|
$record->contextid = $context->id;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue