kronoszx
8/17/2017 - 6:55 PM

Image Upload Size Limit

Image Upload Size Limit

function ecd_limit_image_size($file) {

// Calculate the image size in KB
$image_size = $file['size']/1024;

// File size limit in KB
$limit = 200;

// Check if it's an image
$is_image = strpos($file['type'], 'image');

if ( ( $image_size > $limit ) && ($is_image !== false) )
        $file['error'] = 'Your picture is too large. It has to be smaller than '. $limit .'KB';

return $file;

}
add_filter('wp_handle_upload_prefilter', 'ecd_limit_image_size');