MDL-24410, repository upload plugin allows rename file
This commit is contained in:
@@ -91,6 +91,7 @@ $string['errornotyourfile'] = 'You cannot pick file which is not added by your';
|
||||
$string['erroruniquename'] = 'Repository instance name should be unique';
|
||||
$string['existingrepository'] = 'This repository already exists';
|
||||
$string['federatedsearch'] = 'Federated search';
|
||||
$string['fileexists'] = 'File name already being used, please use another name';
|
||||
$string['filename'] = 'Filename';
|
||||
$string['filenotnull'] = 'You must select a file to upload.';
|
||||
$string['filesaved'] = 'The file has been saved';
|
||||
|
||||
@@ -1006,6 +1006,8 @@ M.core_filepicker.init = function(Y, options) {
|
||||
str += '<tr><td class="mdl-right">';
|
||||
str += '<label for="'+id+'_file">'+data.upload.label+': </label></td>';
|
||||
str += '<td class="mdl-left"><input type="file" id="'+id+'_file" name="repo_upload_file" />';
|
||||
str += '<tr><td class="mdl-right"><label for="newname-'+client_id+'">'+M.str.repository.saveas+':</label></td>';
|
||||
str += '<td class="mdl-left"><input type="text" name="title" id="newname-'+client_id+'" value="" /></td></tr>';
|
||||
str += '<input type="hidden" name="itemid" value="'+this.options.itemid+'" />';
|
||||
for (var i in types) {
|
||||
str += '<input type="hidden" name="accepted_types[]" value="'+types[i]+'" />';
|
||||
|
||||
@@ -251,7 +251,7 @@ switch ($action) {
|
||||
// see MDL-23407
|
||||
try {
|
||||
// TODO: add file scanning MDL-19380 into each plugin
|
||||
$result = $repo->upload();
|
||||
$result = $repo->upload($saveas_filename);
|
||||
echo json_encode($result);
|
||||
} catch (Exception $e) {
|
||||
$err->error = $e->getMessage();
|
||||
|
||||
@@ -41,7 +41,7 @@ class repository_upload extends repository {
|
||||
* Process uploaded file
|
||||
* @return array|bool
|
||||
*/
|
||||
public function upload() {
|
||||
public function upload($saveas_filename) {
|
||||
global $USER, $CFG;
|
||||
|
||||
$types = optional_param('accepted_types', '*', PARAM_RAW);
|
||||
@@ -79,8 +79,10 @@ class repository_upload extends repository {
|
||||
throw new moodle_exception('maxbytes');
|
||||
}
|
||||
|
||||
if (empty($record->filename)) {
|
||||
if (empty($saveas_filename)) {
|
||||
$record->filename = clean_param($_FILES[$elname]['name'], PARAM_FILE);
|
||||
} else {
|
||||
$record->filename = $saveas_filename;
|
||||
}
|
||||
|
||||
if ($this->mimetypes != '*') {
|
||||
@@ -99,11 +101,13 @@ class repository_upload extends repository {
|
||||
}
|
||||
|
||||
if ($file = $fs->get_file($context->id, $record->component, $record->filearea, $record->itemid, $record->filepath, $record->filename)) {
|
||||
return array(
|
||||
'url'=>moodle_url::make_draftfile_url($file->get_itemid(), $file->get_filepath(), $file->get_filename())->out(),
|
||||
'id'=>$file->get_itemid(),
|
||||
'file'=>$file->get_filename()
|
||||
);
|
||||
throw new moodle_exception('fileexists', 'repository');
|
||||
//$record->filename = ;
|
||||
//return array(
|
||||
//'url'=>moodle_url::make_draftfile_url($file->get_itemid(), $file->get_filepath(), $file->get_filename())->out(),
|
||||
//'id'=>$file->get_itemid(),
|
||||
//'file'=>$file->get_filename()
|
||||
//);
|
||||
}
|
||||
|
||||
$record->contextid = $context->id;
|
||||
|
||||
Reference in New Issue
Block a user