49 $size = (int)($userField[
'SETTINGS'][
'SIZE'] ?? 0);
50 $resultExtensions = [];
53 if (isset($userField[
'SETTINGS'][
'EXTENSIONS']))
55 if(is_array($userField[
'SETTINGS'][
'EXTENSIONS']))
57 $extensions = $userField[
'SETTINGS'][
'EXTENSIONS'];
61 $extensions = explode(
',', $userField[
'SETTINGS'][
'EXTENSIONS']);
65 foreach($extensions as $key => $extension)
67 if($extension ===
true)
69 $extension = trim($key);
73 $extension = trim($extension);
76 if(!empty($extension))
78 $resultExtensions[$extension] =
true;
82 $targetBlank = (($userField[
'SETTINGS'][
'TARGET_BLANK'] ??
'Y') ===
'N' ?
'N' :
'Y');
85 'SIZE' => ($size <= 1 ? 20 : ($size > 255 ? 225 : $size)),
86 'LIST_WIDTH' => (int)($userField[
'SETTINGS'][
'LIST_WIDTH'] ?? 0),
87 'LIST_HEIGHT' => (int)($userField[
'SETTINGS'][
'LIST_HEIGHT'] ?? 0),
88 'MAX_SHOW_SIZE' => (int)($userField[
'SETTINGS'][
'MAX_SHOW_SIZE'] ?? 0),
89 'MAX_ALLOWED_SIZE' => (int)($userField[
'SETTINGS'][
'MAX_ALLOWED_SIZE'] ?? 0),
90 'EXTENSIONS' => $resultExtensions,
91 'TARGET_BLANK' => $targetBlank
105 public static function checkFields(array $userField, $value): array
107 if(!is_array($value) && $value)
109 $fileInfo = \CFile::GetFileArray($value);
112 $value = \CFile::MakeFileArray($fileInfo[
'SRC']);
117 empty($userField[
'EDIT_FORM_LABEL'])
118 ? $userField[
'FIELD_NAME']
119 : $userField[
'EDIT_FORM_LABEL']
124 && (!isset($value[
'tmp_name']) && !isset($value[
'old_id']) && !isset($value[
'type']))
129 'id' => $userField[
'FIELD_NAME'],
131 '#FIELD_NAME#' => $fieldName,
142 $userField[
'SETTINGS'][
'MAX_ALLOWED_SIZE'] > 0
144 $value[
'size'] > $userField[
'SETTINGS'][
'MAX_ALLOWED_SIZE']
148 'id' => $userField[
'FIELD_NAME'],
151 '#FIELD_NAME#' => $fieldName,
152 '#MAX_ALLOWED_SIZE#' => $userField[
'SETTINGS'][
'MAX_ALLOWED_SIZE']
160 is_array($userField[
'SETTINGS'][
'EXTENSIONS'])
162 count($userField[
'SETTINGS'][
'EXTENSIONS'])
165 foreach($userField[
'SETTINGS'][
'EXTENSIONS'] as $ext => $tmp_val)
167 $userField[
'SETTINGS'][
'EXTENSIONS'][$ext] = $ext;
169 $error = \CFile::CheckFile(
173 implode(
',', $userField[
'SETTINGS'][
'EXTENSIONS'])
184 'id' => $userField[
'FIELD_NAME'],
191 if(!is_object($USER) || !$USER->IsAdmin())
193 if(HasScriptExtension($value[
'name']))
196 'id' => $userField[
'FIELD_NAME'],
197 'text' =>
Loc::getMessage(
'FILE_BAD_TYPE') .
' (' . $value[
'name'] .
').'
211 $userFieldValues = (is_array($userField[
'VALUE']) ? $userField[
'VALUE'] : [$userField[
'VALUE']]);
212 $valueHasOldId = !empty($value[
'old_id']);
217 $value[
'old_id'] = (is_array($value[
'old_id']) ? $value[
'old_id'] : [$value[
'old_id']]);
218 foreach ($value[
'old_id'] as $key => $oldId)
220 if(!in_array($oldId, $userFieldValues))
222 unset($value[
'old_id'][$key]);
228 foreach ($value[
'old_id'] as $oldId)
230 \CFile::Delete($oldId);
232 $value[
'old_id'] =
false;
238 return (is_array($value[
'old_id']) ? $value[
'old_id'][0] : $value[
'old_id']);
241 $value[
'MODULE_ID'] =
'main';
243 if ($valueHasOldId && is_array($value[
'old_id']))
245 foreach ($value[
'old_id'] as $oldId)
247 \CFile::Delete($oldId);
251 if (!empty($value[
'name']))
255 && is_array($value[
'old_id'])
256 && isset($value[
'ID'])
257 && in_array($value[
'ID'], $value[
'old_id'])
263 return \CFile::SaveFile($value,
'uf');
270 $fileInputUtility = FileInputUtility::instance();
271 $controlId = $fileInputUtility->getUserFieldCid($userField);
275 $delResult = $fileInputUtility->checkDeletedFiles($controlId);
276 if(in_array($value, $delResult))
281 if (is_array($userField[
'VALUE']) && in_array($value, $userField[
'VALUE']))
286 if (!is_array($userField[
'VALUE']) && (
int)$userField[
'VALUE'] === $value)
291 $checkResult = $fileInputUtility->checkFiles($controlId, [$value]);
292 if(!in_array($value, $checkResult))
326 static $maxFileSize =
null;
328 $file = \CFile::MakeFileArray($fileId);
329 if($file && isset($file[
'tmp_name']))
331 if(!isset($maxFileSize))
333 $optionInt = \COption::GetOptionInt(
338 $maxFileSize = $optionInt * 1024;
341 if($maxFileSize > 0 && $file[
'size'] > $maxFileSize)
347 $events = GetModuleEvents(
349 'OnSearchGetFileContent',
352 foreach($events as $event)
354 if($files = ExecuteModuleEventEx($event, [$file[
'tmp_name']]))
362 return $files[
'CONTENT'];