N
N
Nikita Sokolov2020-06-15 12:49:45
1C-Bitrix
Nikita Sokolov, 2020-06-15 12:49:45

Why is the image array not being added to the element?

I made supposedly comments on IB (it’s convenient for me), I made a form for adding a comment with the following handler:

<?
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die('Скрипт должен быть запущен в битриксе');
?>
<?
if($APPLICATION->CaptchaCheckCode($_POST["captcha_word"], $_POST["captcha_code"]) || ($USER->IsAuthorized()))
{


    CModule::IncludeModule('iblock');

    $el = new CIBlockElement;

    $fields = array(
        "DATE_CREATE" => date("d.m.Y H:i:s"),
        "DATE_ACTIVE_FROM" => date("d.m.Y H:i:s"),
        "IBLOCK_ID" => (int) $_POST['iblockID'],
        "NAME" => strip_tags($_POST['authorName']),
        "ACTIVE" => "Y",
        "PREVIEW_TEXT" => strip_tags($_REQUEST['comment']),
        "PREVIEW_PICTURE" => NULL,
        "PROPERTY_VALUES" => [
            "LINKED_USER" => NULL,
            "LINKED_ELEMENT" => $_POST['linkedElement'],
        ]
    );
    
    if ($USER->IsAuthorized()){
        $fields['PREVIEW_PICTURE'] = CFile::GetFileArray($USER->GetParam('PERSONAL_PHOTO'));
        $fields['PROPERTY_VALUES']['LINKED_USER'] = $USER->GetID();
    }

    if ($ID = $el->Add($fields)) {
        echo "Сохранено";
        dump($fields['PREVIEW_PICTURE']);
        $rs = CIBlockElement::GetList(array(), array("ID" => $ID), false, false, array("ID", "PREVIEW_PICTURE")); 
        if($ar = $rs->GetNext()) 
            dump($ar);
        //header('Location: '.$_SERVER['HTTP_REFERER']);
    } else {
        echo '<p>Ошибка при добавлении:<br>'.$el->LAST_ERROR.'</p>';
    }
    
}else{
    die('<p>Капча введена неправильно!</p>');
}
?>


I can't get the add method to add the PREVIEW_PICTURE array to the element. Everything is fine in the first dump, but there is no array in the second one:
5ee744210a411590810657.png

How to fix this?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton, 2020-06-15
@wb_by

The path to the image must start with $_SERVER['DOCUMENT_ROOT']
Examples in the comments
https://dev.1c-bitrix.ru/api_help/iblock/classes/c...
And
How to add images to the infoblock via the API?

S
scottparker, 2020-06-15
@scottparker

in the same place it seems not the array is stored, but the id of the picture

S
smilingcheater, 2020-06-15
@smilingcheater

Why do you want to copy the user's avatar in each review? This is at least not rational. The user ID is already stored in the recall, when displaying the picture, just get his avatar.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question