19 declare(strict_types=1);
44 if (defined(
'ILIAS_DATA_DIR') && defined(
'CLIENT_ID')) {
47 $base_temp_path = sys_get_temp_dir();
50 $this->zip_options = $this->archives->zipOptions();
51 $this->zip_options = $this->zip_options
52 ->withZipOutputPath($base_temp_path);
53 $this->unzip_options = $this->archives->unzipOptions();
60 string $directory_to_zip,
61 string $path_to_output_zip,
62 bool $ensure_top_directory =
false 64 $directory_to_zip = $this->normalizePath($directory_to_zip);
65 $path_to_output_zip = $this->normalizePath($path_to_output_zip);
67 $zip = $this->archives->zip(
70 ->withZipOutputPath(dirname($path_to_output_zip))
71 ->withZipOutputName(basename($path_to_output_zip))
72 ->withDirectoryHandling($ensure_top_directory ? ZipDirectoryHandling::ENSURE_SINGLE_TOP_DIR : ZipDirectoryHandling::KEEP_STRUCTURE)
75 $zip->addDirectory($directory_to_zip);
76 $zip_stream = $zip->get();
78 return $zip_stream->getSize() > 0;
86 ?
string $extract_to_path =
null,
87 bool $overwrite =
false,
89 bool $ensure_top_directory =
false 91 $extract_to_path ??= dirname($path_to_zip);
95 $dir_handling = $ensure_top_directory ? ZipDirectoryHandling::ENSURE_SINGLE_TOP_DIR : ZipDirectoryHandling::KEEP_STRUCTURE;
98 $unzip = $this->archives->unzip(
99 Streams::ofResource(fopen($path_to_zip,
'rb')),
101 ->withZipOutputPath($extract_to_path)
102 ->withOverwrite($overwrite)
103 ->withDirectoryHandling($dir_handling)
105 return $unzip->extract();
Will keep the top directory of the ZIP file if there is one (simple unzip).
zip(string $directory_to_zip, string $path_to_output_zip, bool $ensure_top_directory=false)
UnzipOptions $unzip_options
unzip(string $path_to_zip, ?string $extract_to_path=null, bool $overwrite=false, bool $flat=false, bool $ensure_top_directory=false)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null