ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
AbstractRecursiveZipPreProcessor.php
Go to the documentation of this file.
1<?php
2
20
24
33{
34 use IsMimeTypeOrExtension;
39 abstract protected function checkPath(string $path): bool;
40
41 abstract protected function getRejectionMessage(): string;
42
43 abstract protected function getOKMessage(): string;
44
45 public function process(FileStream $stream, Metadata $metadata): ProcessingStatus
46 {
47 if ($this->isFileAZip($metadata)) {
48 try {
49 $zip_file_path = $stream->getMetadata('uri');
50 $zip = new \ZipArchive();
51 $zip->open($zip_file_path);
52
53 for ($i = 0; $i < $zip->numFiles; $i++) {
54 $original_path = $zip->getNameIndex($i);
55 if (!$this->checkPath($original_path)) {
57 }
58 }
59 $zip->close();
60 } catch (\Throwable) {
62 }
63 }
64
65 if (!$this->checkPath($metadata->getFilename())) {
67 }
68
70 }
71
72 private function isFileAZip(Metadata $metadata): bool
73 {
74 return $this->isMimeTypeOrExtension(
75 $metadata,
76 'zip',
77 ['application/zip', 'application/x-zip-compressed']
78 );
79 }
80}
getFilename()
The filename supplied by the browser.
Definition: Metadata.php:76
process(FileStream $stream, Metadata $metadata)
This method gets invoked by the file upload service to process the file with the help of the processo...
The base interface for all filesystem streams.
Definition: FileStream.php:32
$path
Definition: ltiservices.php:30
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...