73 public function __construct(
private PreProcessorManager $processorManager,
private Filesystems $filesystems,
private GlobalHttpState $globalHttpState)
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]);
90 throw new IllegalStateException($status->getMessage());
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);
115 }
catch (IOException $ex) {
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.');
139 foreach ($this->uploadResult as $key => $uploadResult) {
145 $path = $destination .
'/' . $uploadResult->getName();
148 }
catch (IOException $ex) {
153 $this->uploadResult = $tempResults;
154 $this->uploadStreams =
null;
169 return new UploadResult(
172 $result->getMimeType(),
173 $result->getMetaData(),
174 $result->getStatus(),
190 return new UploadResult(
193 $result->getMimeType(),
194 $result->getMetaData(),
212 return match ($location) {
217 default =>
throw new \InvalidArgumentException(
"No filesystem found for location code \"$location\""),
234 public function register(PreProcessor $preProcessor):
void 236 if (!$this->processed) {
237 $this->processorManager->with($preProcessor);
239 throw new IllegalStateException(
'Can not register processor after the upload was processed.');
249 if ($this->processed) {
250 throw new IllegalStateException(
'Can not reprocess the uploaded files.');
253 $uploadedFiles = $this->globalHttpState->request()->getUploadedFiles();
255 foreach ($collectFilesFromNestedFields as $file) {
256 $metadata =
new Metadata($file->getClientFilename(), $file->getSize(), $file->getClientMediaType());
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);
280 $result =
new UploadResult(
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;
307 $extraMetadata =
new ImmutableMapWrapper(
new EntryLockingStringMap());
308 $result =
new UploadResult(
309 $metadata->getFilename(),
310 $metadata->getUploadSize(),
311 $metadata->getMimeType(),
317 $this->rejectedUploadResult[] = $result;
326 if ($this->processed) {
327 return array_merge($this->uploadResult, $this->rejectedUploadResult);
330 throw new IllegalStateException(
'Can not fetch results without processing the uploads.');
343 $uploadedFiles = $this->
flattenUploadedFiles($this->globalHttpState->request()->getUploadedFiles());
345 return ($uploadedFiles !== []);
354 RecursiveArrayIterator::CHILD_ARRAYS_ONLY
356 RecursiveIteratorIterator::LEAVES_ONLY
359 return iterator_to_array($recursiveIterator,
false);
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...
regenerateUploadResultWithCopyError(UploadResult $result, string $errorReason)
Creates a clone of the given result and set the status to rejected with the passed error message...
selectFilesystem(int $location)
Selects the correct filesystem by the given Location constant.
flattenUploadedFiles(array $uploadedFiles)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
moveFilesTo(string $destination, int $location=Location::STORAGE)
static filesystems()
Returns the loaded filesystems.
__construct(private PreProcessorManager $processorManager, private Filesystems $filesystems, private GlobalHttpState $globalHttpState)
FileUploadImpl constructor.
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.
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.