Site icon Hip-Hop Website Design and Development

restrict file kind and file dimension utilizing media_handle_upload

I’ve a front-end type that through the use of it, customers can submit posts from front-end. all the things is working nice however I’ve one closing downside.

In my type I’ve a file uploader and I am utilizing media_handle_upload for importing person information and it’s working high quality however I am questioning if there’s a method to restrict the file kind and file dimension in media_handle_upload?

I do know that media_handle_upload deal with these! however how can I modify the default conduct?

Right here is my code for add processing:

// Verify that the nonce is legitimate, and the person can edit this submit.
if ( 
    isset( $_POST['my_image_upload_nonce'] ) 
    && wp_verify_nonce( $_POST['my_image_upload_nonce'], 'my_image_upload' )
) {
// The nonce was legitimate and the person has the capabilities, it's secure to proceed.

// These information should be included as dependencies when on the entrance finish.
require_once( ABSPATH . 'wp-admin/consists of/picture.php' );
require_once( ABSPATH . 'wp-admin/consists of/file.php' );
require_once( ABSPATH . 'wp-admin/consists of/media.php' );

// Let WordPress deal with the add.
// Keep in mind, 'my_image_upload' is the title of our file enter in our type above.
$attachment_id = media_handle_upload( 'my_image_upload', $post_id );

if ( is_wp_error( $attachment_id ) ) {
    // There was an error importing the picture.
} else {
    add_post_meta($post_id, 'post_image', $attachment_id, true);
}

} else {

    // The safety test failed, perhaps present the person an error.
}