Здравствуйте, @AlexBern и @ARTUR
Спасибо за ваше сообщение.
В версии 4.18.1 наши разработчики убрали формат SVG из допустимых форматов для загрузки изображений из соображений безопасности: в файле .svg может быть JavaScript.
К сожалению, информация об этом изменении по ошибке не попала в новость о выпуске версии 4.18.1 и в changelog. Приносим свои извинения за доставленные неудобства.
Если вы хотите и дальше пользоваться форматом SVG, вы можете внести следующие изменения в файл config.php вашей установки:
- Убрать строку
'svg',
из
// List of forbidden file extensions (for uploaded files)$config['forbidden_file_extensions'] = array ( 'php', 'php3', 'pl', 'com', 'exe', 'bat', 'cgi', 'htaccess', 'svg',);
- Убрать строку
'image/svg+xml',
из
$config['forbidden_mime_types'] = array ( 'text/x-php', 'text/x-perl', 'text/x-python', 'text/x-shellscript', 'application/x-executable', 'application/x-ms-dos-executable', 'application/x-cgi', 'application/x-extension-htaccess', 'application/x-msdownload', 'image/svg+xml',);
- Добавить строку
'svg',
в
$config['allowed_image_extensions'] = [ 'jpg', 'jpeg', 'png', 'gif', 'ico', 'webp',];
Также в файл /app/Tygh/Tools/ImageHelper.php нужно добавить следующий код:
if ($object_type === 'logos') {
if (!in_array('svg', $supported_formats)) {
$supported_formats[] = 'svg';
}
} elseif (in_array('svg', $supported_formats)) {
$supported_formats = array_filter($supported_formats, static function ($supported_format) {
return $supported_format !== 'svg';
});
}
после
public static function getSupportedFormats($object_type = 'all')
{
$imagine = Tygh::$app['image'];
$supported_formats = array();
if ($imagine instanceof \Imagine\Imagick\Imagine) {
$imagick = new \Imagick();
$supported_formats = array_uintersect(Registry::get('config.allowed_image_extensions'), $imagick->queryFormats(), 'strcasecmp');
$supported_formats = array_map('strtolower', $supported_formats);
$imagick->clear();
$imagick->destroy();
unset($imagick);
} elseif ($imagine instanceof \Imagine\Gd\Imagine) {
$gd_formats = imagetypes();
if ($gd_formats & IMG_JPEG) {
$supported_formats[] = 'jpg';
$supported_formats[] = 'jpeg';
}
if ($gd_formats & IMG_PNG) {
$supported_formats[] = 'png';
}
if ($gd_formats & IMG_GIF) {
$supported_formats[] = 'gif';
}
// phpcs:ignore
if (defined('IMG_WEBP') && ($gd_formats & IMG_WEBP)) {
$supported_formats[] = 'webp';
}
$supported_formats[] = 'ico';
}
Чтобы не изменять файлы ядра, вы можете добавить поддержку svg через хук image_helper_get_supported_formats_post
.