F
F
faragly2015-03-29 12:01:31
1C-Bitrix
faragly, 2015-03-29 12:01:31

How to add an infoblock element with a file ID to DETAIL_PICTURE?

Hello! When adding an element via CIBlockElement::Add(), it crashes if you set DETAIL_PICTURE to the image id or CFile::GetFileArray($id);
In the first and second cases, it returns "The required field "Detailed picture" is not filled.". How to add correctly?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kompi, 2015-03-29
@faragly

Offhand:
It works. I was not too lazy and checked:

$dbElement = CIBlockElement::GetList(array('ID' => 'DESC'), array('IBLOCK_ID' => 23));
while($aElem = $dbElement->Fetch()) {
  var_dump($aElem);
};
$dbElem = new CIBlockElement;
var_dump($dbElem->Add(
    array(
        "NAME" => 'Test2',
        "IBLOCK_ID" => 23,
        'ACTIVE' => 'Y',
        'PREVIEW_TEXT' => 'текст для списка элементов',
        //'DETAIL_PICTURE' => CFile::MakeFileArray(545)
    )
));
var_dump($dbElem->Add(
    array(
        "NAME" => 'Test3',
        "IBLOCK_ID" => 23,
        'ACTIVE' => 'Y',
        'PREVIEW_TEXT' => 'текст для списка элементов',
        'DETAIL_PICTURE' => CFile::MakeFileArray(545)
    )
));

Where 23 is a clean infoblock. Detailed picture required. Created manually 1 element with a detailed picture. The ID of the picture is taken from the element - 545.
We try without the picture and with it. Accordingly, we catch false in the first case and the id of the newly created element.

A
Alexey Emelyanov, 2015-03-29
@babarun

1. First, uncheck the corresponding checkbox in the IB settings and check again (to exclude kernel glitches).
2. Make an empty file (without connecting the site template) in which there will be only CIBlockElement::Add with the addition of an image, let the image lie in the root of the site with the correct file system rights (for accuracy, let everyone have read rights)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question