wpscholar/wp-file-upload-validator

WordPress 文件上传验证器。

1.2.1 2022-01-09 19:29 UTC

This package is auto-updated.

Last update: 2024-09-10 01:17:47 UTC


README

验证文件上传无错误,并且包含正确的文件扩展名、文件类型和/或MIME类型。

安装

composer require wpscholar/wp-file-upload-validator

用法

$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.