ILIAS  release_7 Revision v7.30-3-g800a261c036
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 final public function process(FileStream $stream, Metadata $metadata)
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 (\Exception $e) {
61 return new ProcessingStatus(ProcessingStatus::REJECTED, $e->getMessage());
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}
An exception for terminatinating execution or to throw for unit testing.
getFilename()
The filename supplied by the browser.
Definition: Metadata.php:73
const REJECTED
Upload got rejected by a processor.
process(FileStream $stream, Metadata $metadata)
This method gets invoked by the file upload service to process the file with the help of the processo...
Interface FileStream The base interface for all filesystem streams.
Definition: FileStream.php:18
$i
Definition: metadata.php:24
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...