Skip to content

Commit 4dda63c

Browse files
committed
Added error handling to file upload
1 parent fe3fafd commit 4dda63c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/lang/en/lfm.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
'error-mime' => 'Unexpected MimeType: ',
4545
'error-instance' => 'The uploaded file should be an instance of UploadedFile',
4646
'error-invalid' => 'Invalid upload request',
47+
'error-other' => 'An error has occured: ',
48+
'error-too-large' => 'Request entity too large!',
4749

4850
'btn-upload' => 'Upload File',
4951
'btn-uploading' => 'Uploading...',

src/views/script.blade.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
$('#upload-btn').click(function () {
3838
var options = {
3939
beforeSubmit: showRequest,
40-
success: showResponse
40+
success: showResponse,
41+
error: showError
4142
};
4243
4344
function showRequest(formData, jqForm, options) {
@@ -55,6 +56,17 @@ function showResponse(responseText, statusText, xhr, $form) {
5556
loadItems();
5657
}
5758
59+
function showError(jqXHR, textStatus, errorThrown) {
60+
$('#upload-btn').html('{{ Lang::get("laravel-filemanager::lfm.btn-upload") }}');
61+
if (jqXHR.status == 413) {
62+
notify('{{ Lang::get("laravel-filemanager::lfm.error-too-large") }}');
63+
} else if (textStatus == 'error') {
64+
notify('{{ Lang::get("laravel-filemanager::lfm.error-other") }}' + errorThrown);
65+
} else {
66+
notify('{{ Lang::get("laravel-filemanager::lfm.error-other") }}' + textStatus + '<br>' + errorThrown);
67+
}
68+
}
69+
5870
$('#uploadForm').ajaxSubmit(options);
5971
return false;
6072
});

0 commit comments

Comments
 (0)