wpscholar/wp-file-upload-validator

A file upload validator for WordPress.

1.2.1 2022-01-09 19:29 UTC

This package is auto-updated.

Last update: 2024-11-10 01:37:37 UTC


README

Validate that a file upload has no errors and consists of the correct file extension, file type and/or mime type.

Installation

composer require wpscholar/wp-file-upload-validator

Usage

$file_handle = 'avatar'; // Name of the file input field.

$validator = new wpscholar\WordPress\FileUploadValidator( $file_handle );

$validator->addAllowedFileType( 'image' );
$validator->addAllowedMimeType( 'image/jpeg', 'image/png' );
$validator->addAllowedFileExtension( 'jpg', 'jpeg', 'png' );

$isValid = $validator->isValid(); // Returns "true" or a WP_Error instance containing the error message.