Last active
June 5, 2023 17:54
-
-
Save tomjn/5037437 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
Thank you for the inspiration: https://github.com/szepeviktor/wordpress-plugin-construction/blob/master/mu-image-upload-control/image-upload-control.php