Documentation

GetFileArray

mixed CFile::GetFileArray(
   int FILE_ID,
   $upload_dir = false
)

The method returns an array, describing the file with the specified ID or returns false if the file with such ID does not exist. This method is convenient when both file name and the its path on the server must be retrieved. Static method.

Parameters

Parameter Description Available from version
  FILE_ID   File ID. Fields lineup:
  • ID - file ID.
  • TIMESTAMP_X - date when loaded.
  • MODULE_ID - ID of the module that uploaded the file.
  • HEIGHT - image height.
  • WIDTH - image width.
  • FILE_SIZE - size in bytes.
  • CONTENT_TYPE - File MIME type.
  • SUBDIR - subdirectory inside UPLOAD folder.
  • FILE_NAME - file name after converting and removing incorrect symbols. If the option File upload default folder is set in the Kernel settings, then the name will not differ from ORIGINAL_NAME (parameter will be converted into secure format when the option Automatic replacement of invalid symbols in the uploaded file names is enabled).
  • ORIGINAL_NAME - original file name when the file is uploaded on the server.
  • DESCRIPTION - description.
  • SRC - relative path to DOCUMENT_ROOT.
  • EXTERNAL_ID - external ID of the file.
upload_dir Directory for upload. By default - false.

See Also

CFile Class

Examples of use



//Show image of the announcement of the information block element
//$ELEMENT_ID - ID of this element
if(CModule::IncludeModule('iblock'))
{
$rsElement = CIBlockElement::GetList(
array(),
array("=ID"=>$ELEMENT_ID),
false,
false,
array("PREVIEW_PICTURE")
);
if($arElement = $rsElement->Fetch())
{
$arFile = CFile::GetFileArray($arElement["PREVIEW_PICTURE"]);
if($arFile)
echo '<img src="'.$arFile["SRC"].'" />';
}
}

Get all file properties from elements of the $arResult

array
foreach ($arResult["ITEMS"] as $k=>$v)
{
   foreach ($v["PROPERTIES"] as $kk=>$vv)
   {
      if ($vv["PROPERTY_TYPE"] == "F")
      {
         if ($vv["MULTIPLE"] == "Y")
         {
            foreach ($vv["VALUE"] as $kkk=>$vvv)
            {
               $arResult["ITEMS"][$k]["PROPERTIES"][$kk]["VALUE"][$kkk] = CFile::GetFileArray($vvv);
               $arResult["ITEMS"][$k]["PROPERTIES"][$kk]["VALUE"][$kkk]["DESCRIPTION"] = $vv["DESCRIPTION"][$kkk];
            }
         }
         else
         {
            $arResult["ITEMS"][$k]["PROPERTIES"][$kk]["VALUE"] = CFile::GetFileArray($vv["VALUE"]);
            $arResult["ITEMS"][$k]["PROPERTIES"][$kk]["VALUE"]["DESCRIPTION"] = $vv["DESCRIPTION"];
         }
      }
   }
}

Examples from the component bitrix:news.list

$rsElement = CIBlockElement::GetList($arSort, $arFilter, false, $arNavParams, $arSelect);
while($obElement = $rsElement->GetNextElement())
{
    $arItem = $obElement->GetFields();
    ...
    if(array_key_exists("PREVIEW_PICTURE", $arItem))
        $arItem["PREVIEW_PICTURE"] = CFile::GetFileArray($arItem["PREVIEW_PICTURE"]);
    if(array_key_exists("DETAIL_PICTURE", $arItem))
        $arItem["DETAIL_PICTURE"] = CFile::GetFileArray($arItem["DETAIL_PICTURE"]);
    ...
}


© «Bitrix24», 2001-2024
Up