wpscholar / wp-file-upload-validator
A file upload validator for WordPress.
Installs: 2 814
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
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.