UploadGuard
A helper for dealing with file upload validation.
Constructors / Destructors
| Returns | Signature and Description |
|---|---|
void | __construct()Creates a new UploadGuard. |
Instance Methods
| Returns | Signature and Description |
|---|---|
string | getMimeType(, , )Validates the uploaded files in a request. |
ConstVector<UploadedFileInterface> | getUploadedFiles(, , )Gets the list of uploaded files, validating file size. |
Method Details
__construct
public function
__construct(finfo $finfo)Creates a new UploadGuard.
| Name | Type | Description |
|---|---|---|
$finfo | finfo | The MIME detector |
getMimeType
public function
getMimeType(UploadedFileInterface $file, string $field, ?ConstSet<string> $mimeTypes = null)Validates the uploaded files in a request.
| Name | Type | Description |
|---|---|---|
$file | UploadedFileInterface | The uploaded file |
$field | string | |
$mimeTypes | ?ConstSet<string> | A set of allowed MIME types (e.g. |
| Type | Description |
|---|---|
string | The MIME type |
| Type | Conditions |
|---|---|
Invalid | if the file aren't valid |
getUploadedFiles
public function
getUploadedFiles(ServerRequestInterface $request, string $field, ?int $maxSize = null)Gets the list of uploaded files, validating file size.
| Name | Type | Description |
|---|---|---|
$request | ServerRequestInterface | The PSR HTTP Request |
$field | string | The request field containing the files |
$maxSize | ?int | The maximum allowed file size |
| Type | Description |
|---|---|
ConstVector<UploadedFileInterface> | The uploaded files |
| Type | Conditions |
|---|---|
Invalid | if any files aren't valid |