35use Psr\Http\Message\UploadedFileInterface;
36use RecursiveArrayIterator;
37use RecursiveIteratorIterator;
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]);
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);
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.');
165 $this->uploadResult = $tempResults;
166 $this->uploadStreams =
null;
234 throw new \InvalidArgumentException(
"No filesystem found for location code \"$location\"");
253 if (!$this->processed) {
254 $this->processorManager->with($preProcessor);
266 if ($this->processed) {
270 $uploadedFiles = $this->globalHttpState->request()->getUploadedFiles();
272 foreach ($collectFilesFromNestedFields as $file) {
273 $metadata =
new Metadata($file->getClientFilename(), $file->getSize(), $file->getClientMediaType());
276 }
catch (\RuntimeException
$e) {
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);
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;
334 $this->rejectedUploadResult[] = $result;
343 if ($this->processed) {
344 return array_merge($this->uploadResult, $this->rejectedUploadResult);
360 $uploadedFiles = $this->
flattenUploadedFiles($this->globalHttpState->request()->getUploadedFiles());
362 return ($uploadedFiles !== []);
368 $recursiveIterator =
new RecursiveIteratorIterator(
369 new RecursiveArrayIterator(
371 RecursiveArrayIterator::CHILD_ARRAYS_ONLY
373 RecursiveIteratorIterator::LEAVES_ONLY
376 return iterator_to_array($recursiveIterator,
false);
$location
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class EntryLockingStringMap.
Class ImmutableMapWrapper.
const REJECTED
Upload got rejected by a processor.
const DENIED
Upload got denied by a processor, the upload will be removed immediately.
Class IllegalStateException.
GlobalHttpState $globalHttpState
__construct(PreProcessorManager $processorManager, Filesystems $filesystems, GlobalHttpState $globalHttpState)
FileUploadImpl constructor.
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...
regenerateUploadResultWithCopyError(UploadResult $result, string $errorReason)
Creates a clone of the given result and set the status to rejected with the passed error message.
uploadSizeLimit()
@inheritDoc
selectFilesystem(int $location)
Selects the correct filesystem by the given Location constant.
flattenUploadedFiles(array $uploadedFiles)
regenerateUploadResultWithPath(UploadResult $result, string $path)
Generate an exact copy of the result with the given path.
rejectFailedUpload(Metadata $metadata)
Reject a failed upload with the given metadata.
hasBeenProcessed()
Return (bool)true if the current upload has already been processed.
moveFilesTo(string $destination, int $location=Location::STORAGE)
@inheritDoc
hardRemoveUpload(string $identifier, string $rejection_message)
@description This is the very last thing we can do if a preprocessor DENIEs an upload.
array $rejectedUploadResult
PreProcessorManager $processorManager
static ofPsr7Stream(StreamInterface $stream)
Create a FileStream from a Psr7 compliant stream.
static getUploadSizeLimitBytes()
const TEMPORARY
The ILIAS temporary directory.
const CUSTOMIZING
The filesystem within the web root where all the skins and plugins are saved.
const WEB
The filesystem within the ilias web root.
const STORAGE
The filesystem outside of the ilias web root.
Class PreProcessorManager.
Interface GlobalHttpState.
Class FlySystemFileAccessTest \Provider\FlySystem @runTestsInSeparateProcesses @preserveGlobalState d...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static filesystems()
Returns the loaded filesystems.