Answer the question
In order to leave comments, you need to log in
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
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>
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");
}
});
$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 questionAsk a Question
731 491 924 answers to any question