Answer the question
In order to leave comments, you need to log in
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>');
}
?>
Answer the question
In order to leave comments, you need to log in
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?
in the same place it seems not the array is stored, but the id of the picture
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 questionAsk a Question
731 491 924 answers to any question