Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //title: Картинки коллекций
- \Bitrix\Main\Loader::includeModule('iblock');
- function rbsCheckDir($dirPath, $dirName)
- {
- $collectionDir = $_SERVER["DOCUMENT_ROOT"]."/upload/collection_images/";
- return is_dir($collectionDir.$dirPath) && $dirName != '.' && $dirName != '..';
- }
- $collectionDirSourse = $_SERVER["DOCUMENT_ROOT"]."/upload/collection_images/";
- $ib = 17;
- $dir = opendir($collectionDirSourse);
- $arLog = [];
- while($brand = readdir($dir))
- {
- if(rbsCheckDir($brand, $brand))
- {
- $brandDb = CIblockSection::GetList(['ID' => 'asc'], ['IBLOCK_ID' => $ib, '=NAME' => $brand], false, ['ID', 'NAME']);
- $brandDir = opendir($collectionDirSourse.$brand);
- while($obBrand = $brandDb->GetNext())
- {
- $collectionImg = false;
- while($collection = readdir($brandDir))
- {
- if(rbsCheckDir($brand.'/'.$collection, $collection))
- {
- $collDb = CIblockSection::GetList(['ID' => 'asc'], ['IBLOCK_ID' => $ib, '=NAME' => $collection, 'IBLOCK_SECTION_ID' => $obBrand['ID']], false, ['ID', 'NAME']);
- $collectionDir = opendir($collectionDirSourse.$brand.'/'.$collection);
- while($obCol = $collDb->GetNext())
- {
- while($image = readdir($collectionDir))
- {
- if(strpos($image, '.jpg') !== false)
- {
- $bs = new CIBlockSection;
- $picPath = $collectionDirSourse.$brand.'/'.$collection.'/'.$image;
- $fileArray = CFile::MakeFileArray($picPath);
- $arLoadProductArray = array(
- "PICTURE" => $fileArray
- );
- if(!$bs->Update($obCol['ID'], $arLoadProductArray))
- $arLog[$obCol['ID']] = $el->LAST_ERROR;
- }
- }
- }
- }
- }
- }
- }
- }
- print_r($arLog);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement