Advertisement
animdenis

Section images

May 15th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.68 KB | None | 0 0
  1. //title: Картинки коллекций
  2. \Bitrix\Main\Loader::includeModule('iblock');
  3.  
  4. function rbsCheckDir($dirPath, $dirName)
  5. {
  6.     $collectionDir = $_SERVER["DOCUMENT_ROOT"]."/upload/collection_images/";
  7.     return is_dir($collectionDir.$dirPath) && $dirName != '.' && $dirName != '..';
  8. }
  9.  
  10. $collectionDirSourse = $_SERVER["DOCUMENT_ROOT"]."/upload/collection_images/";
  11. $ib = 17;
  12. $dir = opendir($collectionDirSourse);
  13. $arLog = [];
  14. while($brand = readdir($dir))
  15. {
  16.     if(rbsCheckDir($brand, $brand))
  17.     {
  18.         $brandDb = CIblockSection::GetList(['ID' => 'asc'], ['IBLOCK_ID' => $ib, '=NAME' => $brand], false, ['ID', 'NAME']);
  19.         $brandDir = opendir($collectionDirSourse.$brand);
  20.  
  21.         while($obBrand = $brandDb->GetNext())
  22.         {
  23.             $collectionImg = false;
  24.             while($collection = readdir($brandDir))
  25.             {
  26.                 if(rbsCheckDir($brand.'/'.$collection, $collection))
  27.                 {
  28.                     $collDb = CIblockSection::GetList(['ID' => 'asc'], ['IBLOCK_ID' => $ib, '=NAME' => $collection, 'IBLOCK_SECTION_ID' => $obBrand['ID']], false, ['ID', 'NAME']);
  29.                     $collectionDir = opendir($collectionDirSourse.$brand.'/'.$collection);
  30.                     while($obCol = $collDb->GetNext())
  31.                     {
  32.                         while($image = readdir($collectionDir))
  33.                         {
  34.                             if(strpos($image, '.jpg') !== false)
  35.                             {
  36.                                 $bs = new CIBlockSection;
  37.                                 $picPath = $collectionDirSourse.$brand.'/'.$collection.'/'.$image;
  38.                                 $fileArray = CFile::MakeFileArray($picPath);
  39.                                 $arLoadProductArray = array(
  40.                                     "PICTURE" => $fileArray
  41.                                 );
  42.                                 if(!$bs->Update($obCol['ID'], $arLoadProductArray))
  43.                                     $arLog[$obCol['ID']] = $el->LAST_ERROR;
  44.  
  45.                             }
  46.                         }
  47.                     }
  48.                 }
  49.             }
  50.         }
  51.    }
  52. }
  53.  
  54. print_r($arLog);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement