Allow larger images/videos to be uploaded if they are going to be converted

- 변환 대상인 이미지나 동영상 파일은 용량 제한을 더 느슨하게 설정할 수 있도록 함
- 변환 후에 다시 용량을 체크하여 각 게시판의 업로드 정책 적용
- https://rhymix.org/qna/1926104
This commit is contained in:
Kijin Sung 2026-03-10 19:45:38 +09:00
parent 44cf008ac7
commit 94008fbe9b
10 changed files with 87 additions and 7 deletions

View file

@ -67,9 +67,10 @@ class FileAdminController extends File
{
// Default settings
$config = getModel('module')->getModuleConfig('file') ?: new stdClass;
$config->allowed_filesize = Context::get('allowed_filesize');
$config->allowed_attach_size = Context::get('allowed_attach_size');
$config->allowed_filesize = intval(Context::get('allowed_filesize'));
$config->allowed_attach_size = intval(Context::get('allowed_attach_size'));
$config->allowed_filetypes = Context::get('allowed_filetypes');
$config->pre_conversion_filesize = intval(Context::get('pre_conversion_filesize')) ?: null;
// Image settings
$config->image_autoconv = [];
@ -147,6 +148,28 @@ class FileAdminController extends File
$config->allowed_filetypes = '*.*';
}
// Generate pre-conversion whitelist
$config->pre_conversion_types = [];
foreach ($config->image_autoconv ?? [] as $source_type => $target_type)
{
if (!empty($target_type) && $target_type !== true)
{
$config->pre_conversion_types[] = $source_type;
if ($source_type === 'jpg')
{
$config->pre_conversion_types[] = 'jpeg';
}
}
elseif ($source_type === 'gif2mp4' && $target_type === true)
{
$config->pre_conversion_types[] = 'gif';
}
}
if ($config->video_autoconv['any2mp4'])
{
$config->pre_conversion_types = array_merge($config->pre_conversion_types, ['mp4', 'webm', 'ogv', 'avi', 'mkv', 'mov', 'mpg', 'mpe', 'mpeg', 'wmv', 'm4v', 'flv']);
}
// Save and redirect
$output = getController('module')->insertModuleConfig('file', $config);
$returnUrl = Context::get('success_return_url') ?: getNotEncodedUrl('', 'module', 'admin', 'act', 'dispFileAdminUploadConfig');
@ -206,9 +229,10 @@ class FileAdminController extends File
if(!Context::get('use_default_file_config'))
{
$config->use_default_file_config = 'N';
$config->allowed_filesize = Context::get('allowed_filesize');
$config->allowed_attach_size = Context::get('allowed_attach_size');
$config->allowed_filesize = intval(Context::get('allowed_filesize'));
$config->allowed_attach_size = intval(Context::get('allowed_attach_size'));
$config->allowed_filetypes = Context::get('allowed_filetypes');
$config->pre_conversion_filesize = intval(Context::get('pre_conversion_filesize')) ?: null;
// Check maximum file size
if (PHP_INT_SIZE < 8)
@ -274,6 +298,20 @@ class FileAdminController extends File
$download_grant = Context::get('download_grant');
$config->download_grant = is_array($download_grant) ? array_values($download_grant) : array($download_grant);
// Create pre-conversion whitelist
$config->pre_conversion_types = [];
foreach ($config->image_autoconv ?? [] as $source_type => $target_type)
{
if ($target_type && $target_type !== true)
{
$config->pre_conversion_types[] = $source_type;
if ($source_type === 'jpg')
{
$config->pre_conversion_types[] = 'jpeg';
}
}
}
// Update
$oModuleController = getController('module');
foreach(explode(',', Context::get('target_module_srl')) as $module_srl)