Minimum Upload Size, please!
-
Good day,
Scenario: One of my author always upload images less than 10 kb. This image is very low quality. I’m tired to tell him for upload images more bigger size. When I search in google, i found this code (and work for me):
add_action( 'admin_init', 'wpse_28359_block_authors_from_uploading_small_images' ); function wpse_28359_block_authors_from_uploading_small_images() { if( !current_user_can( 'administrator') ) add_filter( 'wp_handle_upload_prefilter', 'wpse_28359_block_small_images_upload' ); } function wpse_28359_block_small_images_upload( $file ) { // Mime type with dimensions, check to exit earlier $mimes = array( 'image/jpeg', 'image/png', 'image/gif' ); if( !in_array( $file['type'], $mimes ) ) return $file; $img = getimagesize( $file['tmp_name'] ); $minimum = array( 'width' => 640, 'height' => 480 ); if ( $img[0] < $minimum['width'] ) $file['error'] = 'Image too small. Minimum width is ' . $minimum['width'] . 'px. Uploaded image width is ' . $img[0] . 'px'; elseif ( $img[1] < $minimum['height'] ) $file['error'] = 'Image too small. Minimum height is ' . $minimum['height'] . 'px. Uploaded image height is ' . $img[1] . 'px'; return $file; }
My question is: How to make that code to prevent images upload less than 20 kb. Thank you very much.
Kind regards,
Shine
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Minimum Upload Size, please!’ is closed to new replies.