Feature: #104526 - Provide validators for PSR-7 UploadedFile objects in Extbase 

See forge#104526

Description 

4 new Extbase validators have been added to allow common validation tasks of a PSR-7 \TYPO3\CMS\Core\Http\UploadedFile object or an \TYPO3\CMS\Extbase\Persistence\ObjectStorage containing PSR-7 UploadedFile objects.

Note, that the new validators can only be applied to the TYPO3 implementation of the PSR-7 \Psr\Http\Message\UploadedFileInterface because they validate the uploaded files before it has been moved.

Custom implementations of the \UploadedFileInterface must continue to implement their own validators.

FileNameValidator 

This validator ensures, that files with PHP executable file extensions can not be uploaded. The validator has no options.

FileSizeValidator 

This validator can be used to validate an uploaded file against a given minimum and maximum file size.

Validator options:

  • minimum - The minimum size as string (e.g. 100K)
  • maximum - The maximum size as string (e.g. 100K)

MimeTypeValidator 

This validator can be used to validate an uploaded file against a given set of accepted MIME types. The validator additionally verifies, that the given file extension of the uploaded file matches allowed file extensions for the detected mime type.

Validator options:

  • allowedMimeTypes - An array of allowed MIME types
  • ignoreFileExtensionCheck - If set to "true", it is checked, the file extension check is disabled

ImageDimensionsValidator 

This validator can be used to validate an uploaded image for given image dimensions. The validator must only be used, when it is ensured, that the uploaded file is an image (e.g. by validating the MIME type).

Validator options:

  • width - Fixed width of the image as integer
  • height - Fixed height of the image as integer
  • minWidth - Minimum width of the image as integer. Default is 0
  • maxWidth - Maximum width of the image as integer. Default is PHP_INT_MAX
  • minHeight - Minimum height of the image as integer. Default is 0
  • maxHeight - Maximum height of the image as integer. Default is PHP_INT_MAX

Impact 

TYPO3 extension autors can now use the new validators to validate a given UploadedFile object.