O
O
Obivankinobi2016-04-05 16:01:41
PHP
Obivankinobi, 2016-04-05 16:01:41

How to correctly transfer a lot of photos to the Bitrix infoblock?

Good afternoon. There was a problem when transferring several photos from the form on the page to the Bitrix infoblock. Photos are transferred to the infoblock, but they are displayed as icons, but I want to see a preview. prntscr.com/aof091 aof091
And also look at the correct processing of the $_FILES array when passed by ajax, one photo always shows an error ...
the form itself:

<form enctype="multipart/form-data" action="" class="a">
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input name="file[]" multiple type="file">
<input type="submit" class="btn" value="отправить">
</form>

js handler:
var formData = new FormData($('.anketa')[0]); //Получение данных из формы

                    alert(formData);
                        $.ajax({
                type: "POST",
                url: "/send.php",
                cache: false,
                contentType: false,
                processData: false,
                data: formData,
                success: function(data) {
                     console.log(data);
                   },
                   error: function(data){
                    alert("no");
                   }
            });

The request handler itself:
$arFile = array();
foreach ($_FILES["file"]["tmp_name"] as $key =>$value ) {

  if (!$_FILES["file"]["error"][$key]) {
  
    $arFile["n" . $key]=array(
      "VALUE" => CFile::MakeFileArray($value)
      );
  }
}
$arLoadProductArray = Array( 
"PROPERTY_VALUES" => array(	
"PHOTO" => $arFile,
  ) );

if(CModule::IncludeModule("iblock")){
$element = new CIBlockElement; 
$product_ID = $element->Add($arLoadProductArray);
}

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