Skip to content

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

Notifications You must be signed in to change notification settings

wpscholar/wp-file-upload-validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

WordPress File Upload Validator

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.

About

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

Resources

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages