Answer the question
In order to leave comments, you need to log in
How can certain user groups be allowed to upload files that are larger than the specified size in custom fields?
Hello. I would like to add the ability for certain groups of users to upload png files that are larger in resolution than the user field specified in the settings.
In this case, the field on the screen is "Maximum width and height to display in the list". In the form (main.profile - component) in my personal account, I use the field for uploading files (the UF_ user field is responsible for this). Now, as shown in the screenshot, the maximum file resolution should not be more than 1024x512, but for some user groups it is necessary to increase this resolution so that they can upload files with the size I want. How to do it?
Answer the question
In order to leave comments, you need to log in
Set the property to the maximum resolution, and insert the image check into the OnBeforeUserUpdate and OnBeforeUserAdd events.
in /local/php_interface/init.php include the file handlers.php in which lay out the event code
AddEventHandler("main", "OnBeforeUserUpdate", Array("Kudis", "picHandler"));
AddEventHandler("main", "OnBeforeUserAdd", Array("Kudis", "picHandler"));
define("MAX_WIDTH", 10);
define("MAX_HEIGHT", 10);
class Kudis
{
function picHandler(&$arFields)
{
if (is_array($arFields['UF_USERPIC']) && !empty($arFields['UF_USERPIC'])) {
$fileSize = CFile::GetImageSize ($arFields['UF_USERPIC']['tmp_name']);
if ($fileSize[0] > MAX_WIDTH || $fileSize[1] > MAX_HEIGHT) {
global $APPLICATION;
$APPLICATION->throwException('Максимальный размер картинки для Вас: ' . MAX_WIDTH . 'x' . MAX_HEIGHT);
return false;
}
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question