ImageValidator
ImageValidator
Section titled “ImageValidator”Use ImageValidator for a single PHP upload such as a profile or cover image.
Create a rule
Section titled “Create a rule”Rule::image(string $field): ImageValidatorMethods
Section titled “Methods”| Method | Description |
|---|---|
maxFileSizeMB(int $megabytes) | Set the maximum upload size. |
validate(mixed $value) | Validate the uploaded file. |
optional() | Allow no upload. |
isJpegImage(string $contents) | Check JPEG signatures. |
isPngImage(string $contents) | Check PNG signatures. |
isGifImage(string $contents) | Check GIF signatures. |
isBmpImage(string $contents) | Check BMP signatures. |
isTiffImage(string $contents) | Check TIFF signatures. |
isAvifImage(string $contents) | Check AVIF signatures. |
Example
Section titled “Example”use Fynix\Rule;
$validator = Rule::image('profileImage') ->maxFileSizeMB(5);
$error = $validator->validateField($_FILES['profileImage'] ?? null);Fynix checks the upload error, temporary path, size, extension, and actual image content. The default size limit is 5 MB.