A
A
Andrew Sky2015-04-16 12:51:49
PHP
Andrew Sky, 2015-04-16 12:51:49

CFile::ResizeImageGet not working with UF section properties?

In general, the following situation: There are sections in the infoblock and it has a user property file, multiple. It was possible through result_modifer.php to get an array with the paths to the file and place it in the cell I need, but the CFile::ResizeImageGet function refuses to work. What could be the reason? and how to solve this problem? Below are the file listings.
result_modifier.php

//ICON PATH AND PORTFOLIO
foreach($arResult['SECTIONS'] as $key => $sections){
  $arResult["SECTIONS"][$key]["ICON_PATH"] = CFile::GetPath($sections['UF_ICON']);

  if($arResult['SECTION']['ID'] == $sections['ID']){
    foreach($sections["UF_PORTFOLIO"] as $k => $portolio){
      $arResult["SECTION"]["PORTFOLIO"][$k]["ID"] = $portolio;
      $arResult["SECTION"]["PORTFOLIO"][$k]["SRC"] = CFile::GetPath($portolio);
    }
  }
}

template.php
<?if(!empty($arResult["SECTION"]["PORTFOLIO"])){?>
    <section class="portfolio-module">
      <?foreach($arResult["SECTION"]["PORTFOLIO"] as $arPortfolio){
        $resizePhoto = CFile::ResizeImageGet($arPortfolio, array('width'=>500, 'height'=>450), BX_RESIZE_IMAGE_PROPORTIONAL, true);
      ?>
        <img src="<?=$resizePhoto['src'];?>">
      <?}?>
    </section>
  <?}?>

The $arResult array itself looks like this:
[PORTFOLIO] => Array
(
[0] => Array
(
[ID] => 50
[SRC] => /upload/uf/8e6/8e6b6896fd03f0e24e2cd49cc58e562e.jpg
)
[1] => Array
(
[ID] => 51
[SRC] => /upload/uf/565/565686bdc66fab2ad7948b12df2008dc.jpg
)
[2] => Array
(
[ID] => 52
[SRC] => /upload/uf/649/649086d3a8cd0d2653aa4a8e5c93dce7.jpg
)
[3] => Array
(
[ID] => 53
[SRC] => /upload/uf/3f3/3f3a88304ae14cd639174c9f6fa20a19.jpg
)
[4] => Array
(
[ID] => 54
[SRC] => /upload/uf/c06/c06e254494c84b05b7328f48d549b86a.jpg
)
[5] => Array
(
[ID] => 55
[SRC] => /upload/uf/7b3/7b3b703bc04d2f3bfd3b3f071c4ef86e.jpg
)
)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikita, 2015-04-16
@Sky161

1st parameter - File identifier from the b_file table or file description array (Array(FILE_NAME, SUBDIR, WIDTH, HEIGHT, CONTENT_TYPE)) obtained by the GetFileArray method.
Check if what you put in a function fits this description

E
Express777, 2015-04-19
@Express777

In CFile::ResizeImageGet, the ID of the image file must be passed as the first parameter:

<?foreach($arResult["SECTION"]["PORTFOLIO"] as $arPortfolio){
        $resizePhoto = CFile::ResizeImageGet($arPortfolio, array('width'=>500, 'height'=>450), BX_RESIZE_IMAGE_PROPORTIONAL, true);
      ?>
        <img src="<?=$resizePhoto['src'];?>">
      <?}?>

$arPortfolio, judging by the dump, is an array with two keys ID and image path (ID & SRC respectively).
The function will not understand such a parameter.
It could have been written like this:
<?foreach($arResult["SECTION"]["PORTFOLIO"] as $arPortfolio){
        $resizePhoto = CFile::ResizeImageGet($arPortfolio["ID"], array('width'=>500, 'height'=>450), BX_RESIZE_IMAGE_PROPORTIONAL, true);
      ?>
        <img src="<?=$resizePhoto['src'];?>">
      <?}?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question