A
A
Alexander Ivanov2018-02-08 12:07:06
1C-Bitrix
Alexander Ivanov, 2018-02-08 12:07:06

How to add a file from a form to the infoblock property?

There is a form

echo "<form  id='formPromo' enctype='multipart/form-data'>
      Название:<input name='name' value='$name'/>  <br>
      Дата:<input name='date'  type ='date'/><br>
      Описание:<textarea name='discription'></textarea><br>
      Ссылка:<input name='addres' value='$link'/><br><br>
      Картинка:
      <br><br>
       
      <input name='picture' type ='file'  multiple/><br>
      <input name='id' value='$id' type='hidden'/>
      <br><br>
      <input value='Добавить' type='submit'/>
      <input type='hidden' name='clinikID' value='$idClinick'>
  </form>";

It sends data via AJAX
The data is successfully written. But the picture doesn't work.
Handler code
<?php
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");
$APPLICATION->SetTitle("Title");

if(isset($_POST['name'])&&$_POST['name']!="")
{
$name = htmlentities($_POST['name']);
$date = htmlentities($_POST['date']);
$discription = htmlentities($_POST['discription']);
$addres = htmlentities($_POST['addres']);

$id =  htmlentities($_POST['id']);
$clinikID = htmlentities($_POST['clinikID']); 

$picture = $_FILES['picture'];



if (CModule::IncludeModule('iblock')){
    
      
    if($id){
      $arProp["NAME"] = $name;  
            $arProp["LINK"] = $addres;
            $arProp["CLINIK"] = $clinikID;
      
      
      
           $arFields = array(
                'NAME' => $name."-".$date,               
                'MODIFIED_BY' => $USER->GetID(),             
                'IBLOCK_ID' => 13,
                'ACTIVE' => 'Y',
                'PROPERTY_VALUES' => $arProp,
          "IBLOCK_SECTION" => false
            );
     
            $el = new CIBlockElement;
            $intOfferID = $el->Update($id,$arFields);
  
    }else{
    
            $el = new CIBlockElement;
           
            $arProp["NAME"] = $name;  
            $arProp["LINK"] = $addres;	    
            $arProp["CLINIK"] = $clinikID;
      
      
      
           $arFields = array(
                'NAME' => $name."-".$date,               
                'MODIFIED_BY' => $USER->GetID(),             
                'IBLOCK_ID' => 13,
                'ACTIVE' => 'Y',
                'PROPERTY_VALUES' => $arProp
            );
     
      
            $intOfferID = $el->Add($arFields);


    }
  
}

}
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kim, 2018-02-08
@kimono

Something after declaring a variable, $picture = $_FILES['picture'];I do not see its further use. What exactly is missing from the picture?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question