1
0
mirror of https://github.com/monstra-cms/monstra.git synced 2025-07-31 02:10:37 +02:00

Files Manager Improvements - Drug'n'Drop uploader - error handler updates #94

This commit is contained in:
metal_gvc
2014-01-23 00:27:33 +02:00
parent 474fddd803
commit 03045d03ae
4 changed files with 46 additions and 14 deletions

View File

@@ -67,6 +67,11 @@ class FilesmanagerAdmin extends Backend
if (Security::check(Request::get('token'))) {
File::delete($files_path.Request::get('delete_file'));
if (!is_file($files_path.Request::get('delete_file'))) {
Notification::set('success', __('File was deleted', 'system'));
} else {
Notification::set('error', __('File was not deleted', 'system'));
}
Request::redirect($site_url.'/admin/index.php?id=filesmanager&path='.$path);
} else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); }
@@ -98,13 +103,32 @@ class FilesmanagerAdmin extends Backend
if (Security::check(Request::post('csrf'))) {
$error = false;
if ($_FILES['file']) {
if ( ! in_array(File::ext($_FILES['file']['name']), $forbidden_types)) {
move_uploaded_file($_FILES['file']['tmp_name'], $files_path.Security::safeName(basename($_FILES['file']['name'], File::ext($_FILES['file']['name'])), '-', true).'.'.File::ext($_FILES['file']['name']));
Request::redirect($site_url.'/admin/index.php?id=filesmanager&path='.$path);
$filepath = $files_path.Security::safeName(basename($_FILES['file']['name'], File::ext($_FILES['file']['name'])), '-', true).'.'.File::ext($_FILES['file']['name']);
$uploaded = move_uploaded_file($_FILES['file']['tmp_name'], $filepath);
if ($uploaded !== false && is_file($filepath)) {
Notification::set('success', __('File was uploaded', 'system'));
} else {
$error = 'File was not uploaded';
}
} else {
$error = 'Forbidden file type';
}
} else {
$error = 'File was not uploaded';
}
if ($error) {
Notification::set('error', __($error, 'system'));
}
if (Request::post('dragndrop')) {
Request::shutdown();
} else {
Request::redirect($site_url.'/admin/index.php?id=filesmanager&path='.$path);
}
} else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); }
}
@@ -172,7 +196,8 @@ class FilesmanagerAdmin extends Backend
->assign('files_path', $files_path)
->assign('fileuploader', array(
'uploadUrl' => $site_url.'/admin/index.php?id=filesmanager&path='.$path,
'csrf' => Security::token()
'csrf' => Security::token(),
'errorMsg' => __('Upload server error', 'system')
))->display();
}

View File

@@ -4,7 +4,8 @@ $.monstra.fileuploader = {
conf: {
uploadUrl: '',
csrf: ''
csrf: '',
errorMsg: ''
},
init: function(conf){
@@ -45,6 +46,7 @@ $.monstra.fileuploader = {
var fd = new FormData();
fd.append('file', files[i]);
fd.append('upload_file', 'upload_file');
fd.append('dragndrop', '1');
fd.append('csrf', $.monstra.fileuploader.conf.csrf);
//this.setFileNameSize(files[i].name, files[i].size);
@@ -78,11 +80,16 @@ $.monstra.fileuploader = {
success: function(data){
$.monstra.fileuploader.setProgress(100);
location.href = $.monstra.fileuploader.conf.uploadUrl;
/*$('#fuProgress').fadeOut('slow', function(){
$('#fuProgress').css({width: 0, display: 'block'});
$('#fuPlaceholder').show();
});*/
}
},
error: function(){
Messenger().post({
type: 'error',
message : $.monstra.fileuploader.conf.errorMsg,
hideAfter: 3
});
$('#fuProgress').animate({ width: 0 }, 1);
$('#fuPlaceholder').show();
}
});
},

View File

@@ -135,12 +135,12 @@
<div class="modal-content">
<div class="modal-header">
<a class="close" data-dismiss="modal">&times;</a>
<h4 class="modal-title" id="myModalLabel">Create New File</h4>
<h4 class="modal-title">Create New File</h4>
</div>
<div class="modal-body">
<form role="form">
<label for="directoryName">File Name</label>
<input type="text" class="form-control" id="directoryName">
<label for="cdDirectoryName">File Name</label>
<input type="text" class="form-control" id="cdDirectoryName">
</form>
</div>
<div class="modal-footer">