A
A
Antonio_Sk2021-04-07 16:08:29
1C-Bitrix
Antonio_Sk, 2021-04-07 16:08:29

Filling in a multiple property of the File type in infoblocks?

There is a form with a file selection field:

<input type="file" data-not-required name="file" multiple title="Изображения">


2 files (jpg,png images) are sent by POST method asynchronously ( enctype=multipart/form-data):
606dae429ccae408895833.png

\CModule::IncludeModule("iblock");
$el = new \CIBlockElement;
if ($review_id = $el->Add( [
    'IBLOCK_SECTION_ID' => false,
    'IBLOCK_ID' => IBLOCK_content_reviews,
    'PROPERTY_VALUES' => [
"PICTURES" => $FILES['file'],
],
    'NAME' => 'test',
    'ACTIVE' => 'N', 
]))
    \AddMessage2Log(print_r($FILES['file'], true));


1C-Bitrix accepts and saves only one of the files as a property (similarly, var_dump contains only 1 array element, and arrays are not formed as values ​​for name, size, etc. as for several files):

Date: 2021-04-07 15:21:46
Module: 
Array
(
    [name] => Screenshot_1.png
    [type] => image/png
    [tmp_name] => /tmp/phpy1UseU
    [error] => 0
    [size] => 349258
)


array(5) {
  ["name"]=>
  string(27) "Без названия.png"
  ["type"]=>
  string(9) "image/png"
  ["tmp_name"]=>
  string(14) "/tmp/phpvX9khO"
  ["error"]=>
  int(0)
  ["size"]=>
  int(7308)
}


How can you catch both files and force 1C-Bitrix to write them to the multiple property of the file type?

UPD: regarding name="file[]" Bitrix ($el->LAST_ERROR) returns "Invalid file type" for any type allowed in the property (does it not know how to work with arrays?):
606ddf3a05f7e658641350.png
Although file types are explicitly defined for the property:
606ddf4575c01516948592.png
If disable validation of file types, the property is not filled at all (no files are attached). I understand that the question is more likely to support Bitrix for correcting the kernel / file loading module, but perhaps there are any faster solutions for modifying data valid for Bitrix?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question