Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laminas Validator Laravel Package

laminas/laminas-validator

Validation component for PHP and Laminas applications. Provides a wide range of ready-to-use validators (strings, numbers, dates, files, and more), consistent error messages, and an extensible API to create custom validators and input filtering rules.

View on GitHub
Deep Wiki
Context7

MimeType

Laminas\Validator\File\MimeType checks the MIME type of files. It will assert true when a given file matches any defined MIME type.

This validator is inversely related to the ExcludeMimeType validator

NOTE: Compatibility This component makes use of the FileInfo extension which is enabled by default in PHP. If you are using a version of PHP that was explicitly built without the File Info extension, this validator will not work.

Supported Options

The following set of options are supported:

  • mimeType: Comma-delimited string of MIME types, or array of MIME types, against which to test. Types can be specific (e.g., image/jpeg), or refer only to the group (e.g., image).

Basic Usage

use Laminas\Validator\File\MimeType;

// Only allow 'gif' or 'jpg' files
$validator = new MimeType(['mimeType' => 'image/gif,image/jpeg']);

// ... or with array notation:
$validator = new MimeType(['mimeType' => ['image/gif', 'image/jpeg']]);

// ... or restrict to  entire group of types:
$validator = new MimeType(['mimeType' => ['image', 'audio']]);

// Perform validation
if ($validator->isValid('./myfile.jpg')) {
    // file is valid
}

WARNING: Validating MIME Groups Is Potentially Dangerous Allowing "groups" of MIME types will accept all members of this group, even if your application does not support them. For instance, When you allowimage you also allow image/xpixmap and image/vasa, both of which could be problematic.

Validating Uploaded Files

This validator accepts and validates 3 types of argument:

  • A string that represents a path to an existing file
  • An array that represents an uploaded file as per PHP's $_FILES superglobal
  • A PSR-7 UploadedFileInterface instance
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels