PHP code example of wpscholar / wp-file-upload-validator

1. Go to this page and download the library: Download wpscholar/wp-file-upload-validator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wpscholar / wp-file-upload-validator example snippets



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