1С-Битрикс
- 138 ответов
- 0 вопросов
53
Вклад в тег
use Bitrix\Main\EventManager;
EventManager::getInstance()->addEventHandler("main", "OnAfterFileSave", array('MyClass', 'execute'));
EventManager::getInstance()->addEventHandler("main", "OnPhysicalFileDelete", array('MyClass', 'executeDelete'));
EventManager::getInstance()->addEventHandler("main", "OnAfterResizeImage", array('MyClass', 'executeResize'));
class MyClass
{
function execute($arFields)
{
if (intval($arFields['HEIGHT']) > 0 && intval($arFields['WIDTH']) > 0) {
if (strpos($arFields['CONTENT_TYPE'], "image/") !== false && strpos($arFields['CONTENT_TYPE'], "svg") === false)
{
$strPath = \Cfile::GetFileSRC($arFields);
//Make Webp
}
}
}
function executeDelete($arFields)
{
$strPath = \Cfile::GetFileSRC($arFields);
//Delete webp
}
function executeResize($strPath)
{
$obFile = new \Bitrix\Main\IO\File(\Bitrix\Main\Application::getDocumentRoot() . $strPath);
if (strpos($obFile->getContentType(), "image/") !== false && strpos($obFile->getContentType(), "svg") === false) {
//Make Webp
}
}
}
enctype="multipart/form-data"