Last active
October 16, 2023 03:52
-
-
Save SergeyZaigraev/b0db247ef52c4822570986334567679a to your computer and use it in GitHub Desktop.
Bitrix resize image IB. Ресайз изображений инфоблока. Например можно изменить размер картинки анонса у всех товаров. Скрипт пошаговый.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php"); | |
$iblockId = (int)$_REQUEST['iblock']; | |
$page = isset($_REQUEST['page']) ? (int)$_REQUEST['page'] : 1; | |
$pageSize = 70; | |
$isEnd = true; | |
if ($iblockId <= 0) | |
{ | |
ShowError('need define iblock id request'); | |
} | |
else if (!$USER->IsAdmin()) | |
{ | |
ShowError('access denied'); | |
} | |
else if (!\Bitrix\Main\Loader::includeModule('iblock') && !\Bitrix\Main\Loader::includeModule('main')) | |
{ | |
ShowError('require iblock'); | |
} | |
else | |
{ | |
$query = \CIBlockElement::GetList( | |
array( | |
'ID' => 'ASC' | |
), | |
array( | |
'IBLOCK_ID' => $iblockId, | |
), | |
false, | |
array( | |
'iNumPage' => $page, | |
'nPageSize' => $pageSize | |
), | |
array( | |
'IBLOCK_ID', | |
'ID', | |
'PREVIEW_PICTURE', | |
'DETAIL_PICTURE', | |
) | |
); | |
$index = ($page - 1) * $pageSize; | |
$el = new CIBlockElement(); | |
while ($item = $query->Fetch()) | |
{ | |
// $newPict = !$item['PREVIEW_PICTURE'] ? $item['DETAIL_PICTURE']: $item['PREVIEW_PICTURE']; | |
$newPict = $item['DETAIL_PICTURE']; | |
$newPictArr = CFile::GetFileArray($newPict); | |
$src = CFile::MakeFileArray($newPictArr['SRC']); | |
$src['COPY_FILE'] = 'Y'; | |
$res = $el->Update($item['ID'], array("PREVIEW_PICTURE" => $src),false,false,true); | |
$index++; | |
} | |
$isEnd = ($index >= $query->SelectedRowsCount()); | |
} | |
if ($isEnd) | |
{ | |
echo 'Ready!'; | |
} | |
else | |
{ | |
$url = $APPLICATION->GetCurPageParam('page=' . ($page + 1), array('page')); | |
echo 'Progress...'; | |
?> | |
<script> | |
setTimeout(function() { | |
window.location = <?= json_encode($url); ?>; | |
}, 1000); | |
</script> | |
<? | |
} | |
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_after.php"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment