mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-06 18:21:39 +09:00
Enforce allowed filesize and type in extra var upload form
This commit is contained in:
parent
7fe2203cbd
commit
3ffeb63afb
3 changed files with 23 additions and 2 deletions
|
|
@ -11,6 +11,15 @@
|
||||||
});
|
});
|
||||||
$('input.rx_ev_file').on('change', function() {
|
$('input.rx_ev_file').on('change', function() {
|
||||||
const container = $(this).parents('.ev_file_upload');
|
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');
|
container.find('input[type=hidden][name^=_delete_]').val('N');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,19 @@
|
||||||
@endif
|
@endif
|
||||||
@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">
|
<div class="ev_file_input">
|
||||||
<input type="file" name="{{ $input_name }}"
|
<input type="file" name="{{ $input_name }}"
|
||||||
id="{{ $input_id }}"|if="$input_id" class="file rx_ev_file"
|
id="{{ $input_id }}"|if="$input_id" class="file rx_ev_file"
|
||||||
style="{{ $definition->style }}"|if="$definition->style"
|
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)
|
@required(toBool($definition->is_required) && !$value)
|
||||||
@disabled(toBool($definition->is_disabled))
|
@disabled(toBool($definition->is_disabled))
|
||||||
@readonly(toBool($definition->is_readonly))
|
@readonly(toBool($definition->is_readonly))
|
||||||
|
|
|
||||||
|
|
@ -472,9 +472,12 @@ class FileModel extends File
|
||||||
*
|
*
|
||||||
* @return object Returns a file configuration of current module. If user is admin, returns PHP's max file size and allow all file types.
|
* @return object Returns a file configuration of current module. If user is admin, returns PHP's max file size and allow all file types.
|
||||||
*/
|
*/
|
||||||
public static function getUploadConfig()
|
public static function getUploadConfig($module_srl = 0)
|
||||||
{
|
{
|
||||||
$module_srl = Context::get('module_srl') ?: (Context::get('current_module_info')->module_srl ?? 0);
|
if (!$module_srl)
|
||||||
|
{
|
||||||
|
$module_srl = Context::get('module_srl') ?: (Context::get('current_module_info')->module_srl ?? 0);
|
||||||
|
}
|
||||||
$config = self::getFileConfig($module_srl);
|
$config = self::getFileConfig($module_srl);
|
||||||
if (Rhymix\Framework\Session::isAdmin())
|
if (Rhymix\Framework\Session::isAdmin())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue