34use RecursiveArrayIterator;
35use RecursiveIteratorIterator;
84 $file_stream = $this->uploadStreams[$identifier];
85 $uri = $file_stream->getMetadata(
'uri');
86 $file_stream->close();
88 unset($this->uploadStreams[$identifier]);
89 unset($_FILES[$identifier]);
98 if (!$this->processed) {
99 throw new \RuntimeException(
'Can not move unprocessed files.');
109 $path = rtrim($destination,
"/") .
'/' . ($file_name ===
"" ?
$uploadResult->getName() : $file_name);
110 if ($override_existing && $filesystem->has(
$path)) {
111 $filesystem->delete(
$path);
128 if (!$this->processed) {
129 throw new \RuntimeException(
'Can not move unprocessed files.');
133 throw new \RuntimeException(
'Can not move the files a second time.');
153 $this->uploadResult = $tempResults;
154 $this->uploadStreams =
null;
217 default =>
throw new \InvalidArgumentException(
"No filesystem found for location code \"$location\""),
236 if (!$this->processed) {
237 $this->processorManager->with($preProcessor);
249 if ($this->processed) {
253 $uploadedFiles = $this->globalHttpState->request()->getUploadedFiles();
255 foreach ($collectFilesFromNestedFields as $file) {
256 $metadata =
new Metadata($file->getClientFilename(), $file->getSize(), $file->getClientMediaType());
259 }
catch (\RuntimeException) {
265 $identifier = $file->getStream()->getMetadata(
'uri');
267 $identifier = is_array($identifier) ?
'' : $identifier;
269 $this->uploadStreams[$identifier] = $stream;
271 if ($file->getError() === UPLOAD_ERR_OK) {
272 $processingResult = $this->processorManager->process($stream, $metadata);
281 $metadata->getFilename(),
282 $metadata->getUploadSize(),
283 $metadata->getMimeType(),
284 $metadata->additionalMetaData(),
286 is_string($identifier) ? $identifier :
''
288 $this->uploadResult[$identifier] = $result;
294 $this->processed =
true;
317 $this->rejectedUploadResult[] = $result;
326 if ($this->processed) {
327 return array_merge($this->uploadResult, $this->rejectedUploadResult);
343 $uploadedFiles = $this->
flattenUploadedFiles($this->globalHttpState->request()->getUploadedFiles());
345 return ($uploadedFiles !== []);
351 $recursiveIterator =
new RecursiveIteratorIterator(
352 new RecursiveArrayIterator(
354 RecursiveArrayIterator::CHILD_ARRAYS_ONLY
356 RecursiveIteratorIterator::LEAVES_ONLY
359 return iterator_to_array($recursiveIterator,
false);
Class EntryLockingStringMap.
Class ImmutableMapWrapper.
Class IllegalStateException.
hardRemoveUpload(string $identifier, ProcessingStatus $status)
@description This is the very last thing we can do if a preprocessor DENIEs an upload.
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.
__construct(private PreProcessorManager $processorManager, private Filesystems $filesystems, private GlobalHttpState $globalHttpState)
FileUploadImpl constructor.
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
array $rejectedUploadResult
Indicates general problems with the input or output operations.
Stream factory which enables the user to create streams without the knowledge of the concrete class.
static ofPsr7Stream(StreamInterface $stream)
Create a FileStream from a Psr7 compliant stream.
static getPhpUploadSizeLimitInBytes()
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.
The filesystem interface provides the public interface for the Filesystem service API consumer.
The Filesystems interface defines the access methods which can be used to fetch the different filesys...
The base interface for all filesystem streams.
Interface GlobalHttpState.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static filesystems()
Returns the loaded filesystems.