FileValidatorImage
This module implements ProcessWire’s FileValidator interface, which is used by
$sanitizer->validateFile() as part of ProcessWire’s built-in file validations. This is used by existing file uploads, for example. This module adds support for validation of common image bitmap formats: JPG, PNG, GIF.
Copyright 2020 by Ryan Cramer for ProcessWire 3.x
USAGE
You can use from $sanitizer
$valid = $sanitizer->validateFile('/path/to/file.jpg');
if($valid) {
valid image file
} else {
not valid image file
$reason = $sanitizer->errors('last string clear');
echo "Image not valid because: $reason";
}
You can use the module directly if you prefer
This is also useful if you want to specify min/max dimensions
$validator = $modules->get('FileValidatorImage');
$validator->minWidth = 400;
$validator->minHeight = 250;
$validator->maxWidth = 1920;
$validator->maxHeight = 1080;
if($validator->isValid('/path/to/file.jpg')) {
image is valid
} else {
$reason = $validator->getReason();
"Image not valid because: $reason";
} Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the File class also inherits all the methods and properties of: FileValidatorModule, WireData and Wire.
Common
| Name | Return | Summary | |
|---|---|---|---|
File File File | array bool | Get array with image size info | |
File File File | int bool | Get image type that corresponds to PHP IMAGETYPE_* constant | |
File File File | bool string | Return image MIME type, blank if unrecognized or false if unable to open file | |
File File File | string | Get reason why last isValid() call returned false | |
File File File | bool | Does the image have size dimensions that fit minWidth, minHeight, maxWidth, maxHeight? |
Properties
| Name | Return | Summary | |
|---|---|---|---|
| File | int | ||
| File | int | ||
| File | int | ||
| File | int |
Additional methods and properties
In addition to the methods and properties above, File
API reference based on ProcessWire core version 3.0.269