Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
* Plugin Name: Deny Giant Image Uploads
* Description: Prevents Uploads of images greater than 3.2MP
* Author: TJNowell
* Author URI: http://tomjn.com
* Plugin URI: http://tomjn.com/164/clients-who-upload-huge-camera-photos-decompression-bombs/
* Version: 1.1
*/
function tomjn_deny_giant_images($file){
$type = explode('/',$file['type']);
if($type[0] == 'image'){
list( $width, $height, $imagetype, $hwstring, $mime, $rgb_r_cmyk, $bit ) = getimagesize( $file['tmp_name'] );
if($width * $height > 3200728){ // I added 100,000 as sometimes there are more rows/columns than visible pixels depending on the format
$file['error'] = 'This image is too large, resize it prior to uploading, ideally below 3.2MP or 2048x1536';
}
}
return $file;
}
add_filter('wp_handle_upload_prefilter','tomjn_deny_giant_images');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment