34use Psr\Http\Message\UploadedFileInterface;
35use RecursiveArrayIterator;
36use RecursiveIteratorIterator;
96 $this->processed =
false;
98 $this->uploadResult = [];
99 $this->rejectedUploadResult = [];
109 $file_stream = $this->uploadStreams[$identifier];
110 $uri = $file_stream->getMetadata(
'uri');
111 $file_stream->close();
113 unset($this->uploadStreams[$identifier]);
114 unset($_FILES[$identifier]);
123 if ($this->processed ===
false) {
124 throw new \RuntimeException(
'Can not move unprocessed files.');
134 $path = rtrim($destination,
"/") .
'/' . ($file_name ==
"" ?
$uploadResult->getName() : $file_name);
135 if ($override_existing && $filesystem->has($path)) {
136 $filesystem->delete($path);
151 if ($this->processed ===
false) {
152 throw new \RuntimeException(
'Can not move unprocessed files.');
155 if ($this->moved ===
true) {
156 throw new \RuntimeException(
'Can not move the files a second time.');
176 $this->uploadResult = $tempResults;
177 $this->uploadStreams =
null;
247 throw new \InvalidArgumentException(
"No filesystem found for location code \"$location\"");
257 return \ilUtil::getUploadSizeLimitBytes();
266 if ($this->processed ===
false) {
267 $this->processorManager->with($preProcessor);
279 if ($this->processed ===
true) {
286 $uploadedFiles = $this->globalHttpState->request()->getUploadedFiles();
288 foreach ($collectFilesFromNestedFields as $file) {
289 $metadata =
new Metadata($file->getClientFilename(), $file->getSize(), $file->getClientMediaType());
298 $identifier = $file->getStream()->getMetadata(
'uri');
300 $identifier = is_array($identifier) ?
'' : $identifier;
302 $this->uploadStreams[$identifier] = $stream;
304 if ($file->getError() === UPLOAD_ERR_OK) {
305 $processingResult = $this->processorManager->process($stream, $metadata);
314 $metadata->getFilename(),
315 $metadata->getUploadSize(),
316 $metadata->getMimeType(),
317 $metadata->additionalMetaData(),
319 is_string($identifier)?$identifier:
''
321 $this->uploadResult[$identifier] =
$result;
327 $this->processed =
true;
353 $this->rejectedUploadResult[] =
$result;
362 if ($this->processed) {
363 return array_merge($this->uploadResult, $this->rejectedUploadResult);
379 $uploadedFiles = $this->
flattenUploadedFiles($this->globalHttpState->request()->getUploadedFiles());
381 return (count($uploadedFiles) > 0);
392 $recursiveIterator =
new RecursiveIteratorIterator(
393 new RecursiveArrayIterator(
395 RecursiveArrayIterator::CHILD_ARRAYS_ONLY
397 RecursiveIteratorIterator::LEAVES_ONLY
400 return iterator_to_array($recursiveIterator,
false);
An exception for terminatinating execution or to throw for unit testing.
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.
rejectFailedUpload(UploadedFileInterface $file, Metadata $metadata)
Reject a failed upload with the given metadata.
moveFilesTo($destination, $location=Location::STORAGE)
@inheritDoc
regenerateUploadResultWithPath(UploadResult $result, $path)
Generate an exact copy of the result with the given path.
regenerateUploadResultWithCopyError(UploadResult $result, $errorReason)
Creates a clone of the given result and set the status to rejected with the passed error message.
__construct(PreProcessorManager $processorManager, Filesystems $filesystems, GlobalHttpState $globalHttpState)
FileUploadImpl constructor.
flattenUploadedFiles($uploadedFiles)
uploadSizeLimit()
@inheritDoc
hardRemoveUpload(string $identifier)
@description This is the very last thing we can do if a preprocessor DENIEs an upload.
selectFilesystem($location)
Selects the correct filesystem by the given Location constant.
moveOneFileTo(UploadResult $uploadResult, $destination, $location=Location::STORAGE, $file_name='', $override_existing=false)
Moves a single File (the attributes, metadata and upload-status of which are contained in UploadResul...
Class IOException Indicates general problems with the input or output operations.
Class Streams Stream factory which enables the user to create streams without the knowledge of the co...
static ofPsr7Stream(StreamInterface $stream)
Create a FileStream from a Psr7 compliant stream.
process()
Invokes all preprocessors for each uploaded file in the sequence they got registered.
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.
Class Filesystems The Filesystems interface defines the access methods which can be used to fetch the...
Interface FileStream 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.