2 declare(strict_types = 1);
36 public function extract(
string $fileName,
string $directory): bool
40 $zip = new \ZipArchive();
41 $state = $zip->open($fileName);
42 if ($state !==
true) {
44 sprintf(
'Unable to open zip file %s, error code %d', $fileName, $state),
49 $result = $zip->extractTo($directory);
52 GeneralUtility::fixPermissions(rtrim($directory,
'/'),
true);
62 public function verify(
string $fileName): bool
64 $zip = new \ZipArchive();
65 $state = $zip->open($fileName);
66 if ($state !==
true) {
68 sprintf(
'Unable to open zip file %s, error code %d', $fileName, $state),
73 for ($i = 0; $i < $zip->numFiles; $i++) {
74 $entryName = $zip->getNameIndex($i);
75 if (preg_match(
'#/(?:\.{2,})+#', $entryName)
76 || preg_match(
'#^(?:\.{2,})+/#', $entryName)
79 sprintf(
'Suspicious sequence in zip file %s: %s', $fileName, $entryName),
94 if (!is_dir($directory)) {
95 throw new \RuntimeException(
96 sprintf(
'Directory %s does not exist', $directory),
100 if (!is_writable($directory)) {
101 throw new \RuntimeException(
102 sprintf(
'Directory %s is not writable', $directory),