Enforce allowed filesize and type in extra var upload form

This commit is contained in:
Kijin Sung 2024-10-09 11:36:14 +09:00
parent 7fe2203cbd
commit 3ffeb63afb
3 changed files with 23 additions and 2 deletions

View file

@ -11,6 +11,15 @@
});
$('input.rx_ev_file').on('change', function() {
const container = $(this).parents('.ev_file_upload');
const max_size = parseInt($(this).data('allowedFilesize'), 10);
const file_count = this.files.length;
for (let i = 0; i < file_count; i++) {
if (max_size && this.files[i].size > max_size) {
alert($(this).data('msgFilesize'));
$(this).val('');
return;
}
}
container.find('input[type=hidden][name^=_delete_]').val('N');
});
});

View file

@ -16,10 +16,19 @@
@endif
@endif
@php
$file_config = FileModel::getUploadConfig($definition->module_srl);
$allowed_filetypes = strtr($file_config->allowed_filetypes ?? '', ['*.' => '.', ';' => ',']);
$allowed_filesize = ($file_config->allowed_filesize ?? 0) * 1024 * 1024;
@endphp
<div class="ev_file_input">
<input type="file" name="{{ $input_name }}"
id="{{ $input_id }}"|if="$input_id" class="file rx_ev_file"
style="{{ $definition->style }}"|if="$definition->style"
accept="{{ $allowed_filetypes }}"|if="$allowed_filetypes !== '' && $allowed_filetypes !== '*'"
data-allowed-filesize="{{ $allowed_filesize }}"
data-msg-filesize="{{ lang('file.msg_exceeds_limit_size') }}"
@required(toBool($definition->is_required) && !$value)
@disabled(toBool($definition->is_disabled))
@readonly(toBool($definition->is_readonly))