ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
AbstractRecursiveZipPreProcessor.php
Go to the documentation of this file.
1<?php
2
20
24
33{
38 abstract protected function checkPath(string $path) : bool;
39
40 abstract protected function getRejectionMessage() : string;
41
42 abstract protected function getOKMessage() : string;
43
44 final public function process(FileStream $stream, Metadata $metadata)
45 {
46 if ($this->isFileAZip($metadata)) {
47 try {
48 $zip_file_path = $stream->getMetadata('uri');
49 $zip = new \ZipArchive();
50 $zip->open($zip_file_path);
51
52 for ($i = 0; $i < $zip->numFiles; $i++) {
53 $original_path = $zip->getNameIndex($i);
54 if (!$this->checkPath($original_path)) {
56 }
57 }
58 $zip->close();
59 } catch (\Exception $e) {
60 return new ProcessingStatus(ProcessingStatus::REJECTED, $e->getMessage());
61 }
62 }
63
64 if (!$this->checkPath($metadata->getFilename())) {
66 }
67
69 }
70
71 private function isFileAZip(Metadata $metadata) : bool
72 {
73 // is extension zip?
74 if ((substr_compare($metadata->getFilename(), 'zip', -strlen('zip')) === 0) === true) {
75 return true;
76 }
77 // is mime-type zip?
78 $mime_type = strtolower($metadata->getMimeType());
79 if ($mime_type === 'application/zip'
80 || $mime_type === 'application/x-zip-compressed'
81 ) {
82 return true;
83 }
84
85 return false;
86 }
87}
An exception for terminatinating execution or to throw for unit testing.
getFilename()
The filename supplied by the browser.
Definition: Metadata.php:73
getMimeType()
Client supplied mime type of the uploaded.
Definition: Metadata.php:118
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...
$i
Definition: metadata.php:24
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...