83 $this->processed =
false;
85 $this->uploadResult = [];
86 $this->rejectedUploadResult = [];
96 $file_stream = $this->uploadStreams[$identifier];
97 $uri = $file_stream->getMetadata(
'uri');
98 $file_stream->close();
100 unset($this->uploadStreams[$identifier]);
101 unset($_FILES[$identifier]);
102 throw new IllegalStateException($status->getMessage());
110 if (!$this->processed) {
111 throw new \RuntimeException(
'Can not move unprocessed files.');
121 $path = rtrim($destination,
"/") .
'/' . ($file_name ===
"" ? $uploadResult->getName() : $file_name);
122 if ($override_existing && $filesystem->has(
$path)) {
123 $filesystem->delete(
$path);
127 }
catch (IOException $ex) {
140 if (!$this->processed) {
141 throw new \RuntimeException(
'Can not move unprocessed files.');
145 throw new \RuntimeException(
'Can not move the files a second time.');
151 foreach ($this->uploadResult as $key => $uploadResult) {
157 $path = $destination .
'/' . $uploadResult->getName();
160 }
catch (IOException $ex) {
165 $this->uploadResult = $tempResults;
166 $this->uploadStreams = null;
181 return new UploadResult(
184 $result->getMimeType(),
185 $result->getMetaData(),
186 $result->getStatus(),
202 return new UploadResult(
205 $result->getMimeType(),
206 $result->getMetaData(),
234 throw new \InvalidArgumentException(
"No filesystem found for location code \"$location\"");
251 public function register(PreProcessor $preProcessor):
void 253 if (!$this->processed) {
254 $this->processorManager->with($preProcessor);
256 throw new IllegalStateException(
'Can not register processor after the upload was processed.');
266 if ($this->processed) {
267 throw new IllegalStateException(
'Can not reprocess the uploaded files.');
270 $uploadedFiles = $this->globalHttpState->request()->getUploadedFiles();
272 foreach ($collectFilesFromNestedFields as $file) {
273 $metadata =
new Metadata($file->getClientFilename(), $file->getSize(), $file->getClientMediaType());
282 $identifier = $file->getStream()->getMetadata(
'uri');
284 $identifier = is_array($identifier) ?
'' : $identifier;
286 $this->uploadStreams[$identifier] = $stream;
288 if ($file->getError() === UPLOAD_ERR_OK) {
289 $processingResult = $this->processorManager->process($stream, $metadata);
297 $result =
new UploadResult(
298 $metadata->getFilename(),
299 $metadata->getUploadSize(),
300 $metadata->getMimeType(),
301 $metadata->additionalMetaData(),
303 is_string($identifier) ? $identifier :
'' 305 $this->uploadResult[$identifier] = $result;
311 $this->processed =
true;
324 $extraMetadata =
new ImmutableMapWrapper(
new EntryLockingStringMap());
325 $result =
new UploadResult(
326 $metadata->getFilename(),
327 $metadata->getUploadSize(),
328 $metadata->getMimeType(),
334 $this->rejectedUploadResult[] = $result;
343 if ($this->processed) {
344 return array_merge($this->uploadResult, $this->rejectedUploadResult);
347 throw new IllegalStateException(
'Can not fetch results without processing the uploads.');
360 $uploadedFiles = $this->
flattenUploadedFiles($this->globalHttpState->request()->getUploadedFiles());
362 return ($uploadedFiles !== []);
371 RecursiveArrayIterator::CHILD_ARRAYS_ONLY
373 RecursiveIteratorIterator::LEAVES_ONLY
376 return iterator_to_array($recursiveIterator,
false);
const REJECTED
Upload got rejected by a processor.
const STORAGE
The filesystem outside of the ilias web root.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
GlobalHttpState $globalHttpState
regenerateUploadResultWithCopyError(UploadResult $result, string $errorReason)
Creates a clone of the given result and set the status to rejected with the passed error message...
$location
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
selectFilesystem(int $location)
Selects the correct filesystem by the given Location constant.
flattenUploadedFiles(array $uploadedFiles)
__construct(PreProcessorManager $processorManager, Filesystems $filesystems, GlobalHttpState $globalHttpState)
FileUploadImpl constructor.
PreProcessorManager $processorManager
moveFilesTo(string $destination, int $location=Location::STORAGE)
static filesystems()
Returns the loaded filesystems.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
array $rejectedUploadResult
rejectFailedUpload(Metadata $metadata)
Reject a failed upload with the given metadata.
moveOneFileTo(UploadResult $uploadResult, string $destination, int $location=Location::STORAGE, string $file_name='', bool $override_existing=false)
Moves a single File (the attributes, metadata and upload-status of which are contained in UploadResul...
const CUSTOMIZING
The filesystem within the web root where all the skins and plugins are saved.
hasBeenProcessed()
Return (bool)true if the current upload has already been processed.
const DENIED
Upload got denied by a processor, the upload will be removed immediately.
regenerateUploadResultWithPath(UploadResult $result, string $path)
Generate an exact copy of the result with the given path.
const TEMPORARY
The ILIAS temporary directory.
static getPhpUploadSizeLimitInBytes()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const WEB
The filesystem within the ilias web root.
hardRemoveUpload(string $identifier, ProcessingStatus $status)
This is the very last thing we can do if a preprocessor DENIEs an upload.
static ofPsr7Stream(StreamInterface $stream)
Create a FileStream from a Psr7 compliant stream.