Advertisement
animdenis

Zip Dirs unpack

May 15th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. //title: Распакова архивов
  2.  
  3. $collectionDir = $_SERVER["DOCUMENT_ROOT"]."/upload/collection_images/";
  4. $dir = opendir($collectionDir);
  5. $zipFilesDir = [];
  6. while($collection = readdir($dir))
  7. {
  8.     if (is_dir($collectionDir.$collection) && $collection != '.' && $collection != '..')
  9.     {
  10.         $section = opendir($collectionDir.$collection);
  11.         while($file = readdir($section))
  12.         {
  13.             if($file != '.' && $file != '..' && strpos($file, '.zip') !== false)
  14.                 $zipFilesDir[$collectionDir.$collection.'/'][] = $file;
  15.         }
  16.    }
  17. }
  18.  
  19. // Параметры распаковки
  20. $arUnpackOptions = Array(
  21.    "REMOVE_PATH"      => $_SERVER["DOCUMENT_ROOT"],
  22.    "UNPACK_REPLACE"   => false
  23. );
  24.  
  25. $arResult = [];
  26. foreach($zipFilesDir as $zipDir => $zipFiles)
  27. {
  28.     $sFilePathDst = $zipDir;
  29.     foreach($zipFiles as $zipFile)
  30.     {
  31.         $sFilePathArc = $zipDir.$zipFile;
  32.         $resArchiver = CBXArchive::GetArchive($sFilePathArc);
  33.         $resArchiver->SetOptions($arUnpackOptions);
  34.         $uRes = $resArchiver->Unpack($sFilePathDst);
  35.             if (!$uRes) {
  36.                $arResult[$zipDir][$zipFile] = $arc->GetErrors();
  37.             } else {
  38.                $arResult[$zipDir][$zipFile] = 'success';
  39.             }
  40.     }
  41. }
  42.  
  43. print_r($arResult);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement