A
A
Alexey Verkhovtsev2016-08-09 11:58:33
PHP
Alexey Verkhovtsev, 2016-08-09 11:58:33

How to get links to files?

Hello, there are 2 infoblocks, in one there are 2 additional ones. fields for uploading files, one field for uploading files in PDF, others in DOC, in another infoblock the "File" FILES field, which leads to the infoblock with files. As a result, when I display an infoblock with articles in them, I need to display these 2 links to the file, when I print the array, I see this picture

[FILES] => Array
                (
                    [ID] => 6
                    [TIMESTAMP_X] => 2016-08-09 14:04:48
                    [IBLOCK_ID] => 2
                    [NAME] => Файлы
                    [ACTIVE] => Y
                    [SORT] => 500
                    [CODE] => FILES
                    [DEFAULT_VALUE] => 
                    [PROPERTY_TYPE] => E
                    [ROW_COUNT] => 1
                    [COL_COUNT] => 30
                    [LIST_TYPE] => L
                    [MULTIPLE] => N
                    [XML_ID] => 
                    [FILE_TYPE] => 
                    [MULTIPLE_CNT] => 5
                    [TMP_ID] => 
                    [LINK_IBLOCK_ID] => 5
                    [WITH_DESCRIPTION] => N
                    [SEARCHABLE] => N
                    [FILTRABLE] => N
                    [IS_REQUIRED] => N
                    [VERSION] => 1
                    [USER_TYPE] => EList
                    [USER_TYPE_SETTINGS] => Array
                        (
                            [size] => 1
                            [width] => 0
                            [group] => N
                            [multiple] => N
                        )

                    [HINT] => 
                    [PROPERTY_VALUE_ID] => 39
                    [VALUE] => 46
                    [DESCRIPTION] => 
                    [VALUE_ENUM] => 
                    [VALUE_XML_ID] => 
                    [VALUE_SORT] => 
                    [~VALUE] => 46
                    [~DESCRIPTION] => 
                    [~NAME] => Файлы
                    [~DEFAULT_VALUE] => 
                )

How can I get 2 links to my files from this?
That is, I see that in the [VALUE] => 46 field, this is my article in the info block. 39d6e0ee921e465d8dd2945f36cc8d0d.pngTherefore, I think you need to first pull it into an array, and then pull out two fields from it, right? If so, how can I get an article by this id?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman, 2016-08-09
@r_zaycev

If you write your own in a component (which is unlikely), then do this:

$res = CIBlockElement::GetList(
 array(),
 array(
 'IBLOCK_ID' = 1, // Идентификатор ИБ статей
 ),
 false,
 false,
 array(
  'PROPERTY_FILES.PROPERTY_DOC', // Коды свойств с файлами
  'PROPERTY_FILES.PROPERTY_PDF'
 )
);

while($arFields = $res->GetNext()){
 // Смотрите, что тут находится в $arFields, и доставайте файлы по идентификатору, с помощью метода CFile::GetByID либо CFile::GetPath
}

Links to documentation: https://dev.1c-bitrix.ru/api_help/iblock/classes/c...
https://dev.1c-bitrix.ru/api_help/main/reference/c...
https: //dev.1c-bitrix.ru/api_help/main/reference/c...
If you want to display a standard component in the template (news.detail, apparently), then use the result_modifier.php file of the component template, get the links on files there and write to $arResult ( dock ). Like this:
result_modifier.php:
if(!empty($arResult['PROPERTIES']['FILES']['VALUE'])){
 $res = CIBlockElement::GetList(
  array(),
  array(
   'IBLOCK_ID' => $arResult['PROPERTIES']['FILES']['IBLOCK_ID'],
   'ID' => $arResult['PROPERTIES']['FILES']['VALUE'],
   'ACTIVE' => 'Y' 
  ),
  false,
  false,
  array(
   'PROPERTY_DOC', // Коды свойств с файлами
   'PROPERTY_PDF'
  )
 );

 $files = array();

 while($arFields = $res->GetNext()){
  foreach(array('PDF', 'DOC') as $code){
   $fullCode = "PROPERTY_$code_VALUE";
   if($filePath = CFile::GetPath($arFields[$fullCode])){
    $files[] = $filePath;
   }
  }
 }
 $arResult['PROPERTIES']['FILES']['LINKS'] = $files;
}

I don't guarantee the code will work, I wrote it from memory, but the idea, I think, is clear.

A
Alexey Verkhovtsev, 2016-08-09
@seftomsk

I pulled out the material with 46 id, but in the end I don’t know how to pull out 2 fields from it

Array
(
    [ID] => 46
    [~ID] => 46
    [TIMESTAMP_X] => 09.08.2016 14:03:21
    [~TIMESTAMP_X] => 09.08.2016 14:03:21
    [TIMESTAMP_X_UNIX] => 1470729801
    [~TIMESTAMP_X_UNIX] => 1470729801
    [MODIFIED_BY] => 1
    [~MODIFIED_BY] => 1
    [DATE_CREATE] => 09.08.2016 14:03:21
    [~DATE_CREATE] => 09.08.2016 14:03:21
    [DATE_CREATE_UNIX] => 1470729801
    [~DATE_CREATE_UNIX] => 1470729801
    [CREATED_BY] => 1
    [~CREATED_BY] => 1
    [IBLOCK_ID] => 5
    [~IBLOCK_ID] => 5
    [IBLOCK_SECTION_ID] => 
    [~IBLOCK_SECTION_ID] => 
    [ACTIVE] => Y
    [~ACTIVE] => Y
    [ACTIVE_FROM] => 
    [~ACTIVE_FROM] => 
    [ACTIVE_TO] => 
    [~ACTIVE_TO] => 
    [DATE_ACTIVE_FROM] => 
    [~DATE_ACTIVE_FROM] => 
    [DATE_ACTIVE_TO] => 
    [~DATE_ACTIVE_TO] => 
    [SORT] => 500
    [~SORT] => 500
    [NAME] => Авторское право
    [~NAME] => Авторское право
    [PREVIEW_PICTURE] => 
    [~PREVIEW_PICTURE] => 
    [PREVIEW_TEXT] => 
    [~PREVIEW_TEXT] => 
    [PREVIEW_TEXT_TYPE] => text
    [~PREVIEW_TEXT_TYPE] => text
    [DETAIL_PICTURE] => 
    [~DETAIL_PICTURE] => 
    [DETAIL_TEXT] => 
    [~DETAIL_TEXT] => 
    [DETAIL_TEXT_TYPE] => text
    [~DETAIL_TEXT_TYPE] => text
    [SEARCHABLE_CONTENT] => АВТОРСКОЕ ПРАВО


    [~SEARCHABLE_CONTENT] => АВТОРСКОЕ ПРАВО


    [WF_STATUS_ID] => 1
    [~WF_STATUS_ID] => 1
    [WF_PARENT_ELEMENT_ID] => 
    [~WF_PARENT_ELEMENT_ID] => 
    [WF_LAST_HISTORY_ID] => 
    [~WF_LAST_HISTORY_ID] => 
    [WF_NEW] => 
    [~WF_NEW] => 
    [LOCK_STATUS] => green
    [~LOCK_STATUS] => green
    [WF_LOCKED_BY] => 
    [~WF_LOCKED_BY] => 
    [WF_DATE_LOCK] => 
    [~WF_DATE_LOCK] => 
    [WF_COMMENTS] => 
    [~WF_COMMENTS] => 
    [IN_SECTIONS] => N
    [~IN_SECTIONS] => N
    [SHOW_COUNTER] => 
    [~SHOW_COUNTER] => 
    [SHOW_COUNTER_START] => 
    [~SHOW_COUNTER_START] => 
    [CODE] => avtorskoe-pravo
    [~CODE] => avtorskoe-pravo
    [TAGS] => 
    [~TAGS] => 
    [XML_ID] => 46
    [~XML_ID] => 46
    [EXTERNAL_ID] => 46
    [~EXTERNAL_ID] => 46
    [TMP_ID] => 0
    [~TMP_ID] => 0
    [USER_NAME] => (seftomsk) Алексей Верховцев
    [~USER_NAME] => (seftomsk) Алексей Верховцев
    [LOCKED_USER_NAME] => 
    [~LOCKED_USER_NAME] => 
    [CREATED_USER_NAME] => (seftomsk) Алексей Верховцев
    [~CREATED_USER_NAME] => (seftomsk) Алексей Верховцев
    [LANG_DIR] => /
    [~LANG_DIR] => /
    [LID] => s1
    [~LID] => s1
    [IBLOCK_TYPE_ID] => services
    [~IBLOCK_TYPE_ID] => services
    [IBLOCK_CODE] => files
    [~IBLOCK_CODE] => files
    [IBLOCK_NAME] => Файлы
    [~IBLOCK_NAME] => Файлы
    [IBLOCK_EXTERNAL_ID] => 
    [~IBLOCK_EXTERNAL_ID] => 
    [DETAIL_PAGE_URL] => /services/detail.php?ID=46
    [~DETAIL_PAGE_URL] => /services/detail.php?ID=46
    [LIST_PAGE_URL] => /services/index.php?ID=5
    [~LIST_PAGE_URL] => /services/index.php?ID=5
    [CANONICAL_PAGE_URL] => 
    [~CANONICAL_PAGE_URL] => 
    [CREATED_DATE] => 2016.08.09
    [~CREATED_DATE] => 2016.08.09
    [BP_PUBLISHED] => Y
    [~BP_PUBLISHED] => Y
)

I'm doing something wrong

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question