D
D
Denis Vyachenkov2016-08-30 23:09:25
1C-Bitrix
Denis Vyachenkov, 2016-08-30 23:09:25

Bitrix. How to upload a file and get its id?

Hello! I ask for help in the implementation. In general, there is a form for uploading images, which I write myself, without using built-in components. The form must load a picture into the "file" type property. How to implement it in Bitrix? The problem is in loading and getting the id, writing to the property occurs if you manually write the id of an already loaded image.
< form name="iblock_add" id="iblock_add" method="POST" action="<?=POST_FORM_ACTION_URI?>" enctype="multipart/form-data" >
$value = $arResult["PROPERTIES"][$propertyName ]['ID']['VALUE'];
< input type="hidden" name="PROPERTY[<?=$arResult['PROPERTIES'][$propertyName]['ID']?>][0]" value="<?=$value?>">
< input type="submit" class="submitbutton" name="<?if(!$arResult["UPDATE"]):?>submit_iblock_add<?else:?>submit_iblock_update<?endif?>" value="SAVE" />
</form>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Mikhailovich, 2016-08-31
@vsyakiyjr

The article is fresh - I just read it - https://dev.1c-bitrix.ru/community/webdev/user/640...
I solved your problem like this, I really don’t understand the meaning

<form action="" method="POST">
<?foreach ($_POST["NEW_FILE_UPLOAD"] as $key => $item):?>
  <?$img = htmlspecialchars($item);?>
  <img src="<?=CFIle::GetPath($img)?>" width="150px">
<?endforeach?>
<?$APPLICATION->IncludeComponent("bitrix:main.file.input", "drag_n_drop",
   array(
      "INPUT_NAME"=>"NEW_FILE_UPLOAD",
      "MULTIPLE"=>"Y",
      "MODULE_ID"=>"main",
      "MAX_FILE_SIZE"=>"",
      "ALLOW_UPLOAD"=>"A", 
      "ALLOW_UPLOAD_EXT"=>"",
    "INPUT_CAPTION" => "Добавить фото",
    "INPUT_VALUE" => $_POST['NEW_FILE_UPLOAD']
   ),
   false
);?>
  <input class="pic" type="text" value="" id="newF">
  <input type="submit" value="Отправить">
</form>

in script.js component inserted at the end of window.BlogBFileDialogUploader.prototype.Callback
var inp = BX("newF");
  BX.adjust(inp, {props: {value: result.element_id}});

After uploading a file, you can get an id in the form field, display images after uploading - yes, there are a lot of possibilities

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question