Enforce file limits

merge-requests/3/head
Mike Koch 8 years ago
parent 3ea316388c
commit 1eeb477577

@ -1836,4 +1836,11 @@ function mfh_log_warning($location, $message, $user) {
function mfh_log_error($location, $message, $user) { function mfh_log_error($location, $message, $user) {
mfh_log($location, $message, 3, $user); mfh_log($location, $message, 3, $user);
}
function mfh_bytesToUnits($size) {
$bytes_in_megabyte = 1048576;
$quotient = $size / $bytes_in_megabyte;
return intval($quotient);
} }

@ -211,6 +211,8 @@ function display_dropzone_field($url, $id = 'filedrop') {
output_attachment_id_holder_container($id); output_attachment_id_holder_container($id);
$acceptedFiles = implode(',', $hesk_settings['attachments']['allowed_types']); $acceptedFiles = implode(',', $hesk_settings['attachments']['allowed_types']);
$size = mfh_bytesToUnits($hesk_settings['attachments']['max_size']);
$max_files = $hesk_settings['attachments']['max_number'];
echo " echo "
<script type=\"text/javascript\"> <script type=\"text/javascript\">
@ -224,22 +226,29 @@ function display_dropzone_field($url, $id = 'filedrop') {
file['databaseId'] = response; file['databaseId'] = response;
}); });
this.on('removedfile', function(file) { this.on('removedfile', function(file) {
// Remove the attachment from the database and the filesystem.
removeAttachment(file['databaseId']); removeAttachment(file['databaseId']);
}); });
this.on('queuecomplete', function(progress) { this.on('queuecomplete', function(progress) {
// Stop animating if complete.
$('#total-progress').removeClass('active'); $('#total-progress').removeClass('active');
}); });
}, },
paramName: 'attachment', paramName: 'attachment',
url: '" . $url . "', url: '" . $url . "',
parallelUploads: 1, parallelUploads: ".$max_files.",
uploadMultiple: false, uploadMultiple: true,
maxFiles: 1, maxFiles: ".$max_files.",
acceptedFiles: '".json_encode($acceptedFiles)."', acceptedFiles: '".json_encode($acceptedFiles)."',
maxFilesize: 2, // MB maxFilesize: ".$size.", // MB
dictDefaultMessage: ".json_encode($hesklang['attachment_viewer_message']).", dictDefaultMessage: ".json_encode($hesklang['attachment_viewer_message']).",
dictFallbackMessage: '',
dictInvalidFileType: ".json_encode($hesklang['attachment_invalid_type_message']).", dictInvalidFileType: ".json_encode($hesklang['attachment_invalid_type_message']).",
dictResponseError: ".json_encode($hesklang['attachment_upload_error']).", dictResponseError: ".json_encode($hesklang['attachment_upload_error']).",
dictFileTooBig: ".json_encode($hesklang['attachment_too_large']).",
dictCancelUpload: ".json_encode($hesklang['attachment_cancel']).",
dictCancelUploadConfirmation: ".json_encode($hesklang['attachment_confirm_cancel']).",
dictRemoveFile: ".json_encode($hesklang['attachment_remove']).",
previewTemplate: $('#previews').html() previewTemplate: $('#previews').html()
}; };
</script> </script>

@ -35,6 +35,10 @@ $hesklang['can_view_logs'] = 'Can view message logs';
$hesklang['attachment_viewer_message'] = 'Drag or click here to select files to upload.'; $hesklang['attachment_viewer_message'] = 'Drag or click here to select files to upload.';
$hesklang['attachment_invalid_type_message'] = 'Sorry, but the file type you tried to upload is not allowed.'; $hesklang['attachment_invalid_type_message'] = 'Sorry, but the file type you tried to upload is not allowed.';
$hesklang['attachment_upload_error'] = 'An error occurred when trying to upload. Please try again later.'; $hesklang['attachment_upload_error'] = 'An error occurred when trying to upload. Please try again later.';
$hesklang['attachment_too_large'] = 'This attachment is larger than the max filesize permitted.';
$hesklang['attachment_cancel'] = 'Cancel';
$hesklang['attachment_confirm_cancel'] = 'Are you sure you want to cancel this upload?';
$hesklang['attachment_remove'] = 'Remove attachment';
// ADDED OR MODIFIED IN Mods for HESK 2.5.2 // ADDED OR MODIFIED IN Mods for HESK 2.5.2
$hesklang['manage_statuses'] = 'Manage Statuses'; $hesklang['manage_statuses'] = 'Manage Statuses';

Loading…
Cancel
Save