MyBB Community Forums

Full Version: Limit Signature Image Size in kilobyte
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Create limitsign.php in Notepad ++

and copy (or you can use attached file)

<?php 
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

// Plugin info
function limitsign_info ()
{
	return array(
		"name"			=> "limitsign",
		"description"	=> "limitsign",
		"website"		=> "limitsign",
		"author"		=> "limitsign",
		"authorsite"	=> "limitsign",
		"version"		=> "limitsign",
		"guid" 			=> "limitsign",
		"compatibility" => "16*"
	);
}

$plugins->add_hook('usercp_start', 'signsize');
function signsize()
{
    global $mybb, $error;

    preg_match_all("/\[img(.*?)\](.*?)\[\/img\]/i", $mybb->input['signature'], $matches, PREG_SET_ORDER);

	$kbsizetot = 0;
	
	foreach ($matches as $img)
	{
	$kbsize = strlen(@file_get_contents($img[2]));
	$kbsizetot += $kbsize;
	}
    
    if (($kbsizetot > 350000) && ($mybb->input['action'] == "do_editsig")) {

    $error = inline_error("The sum of the size of the images exceeds the allowed limit of 350kb.");

    }	
}
?>

Change "350000" with value you want...
350000 is same 350 kb
100000 is same 100 kb.....

Change "The sum of the size of the images exceeds the allowed limit of 350kb." with error message you want.

upload limitsign.php to plugin folder and activate.
it´s all.
New version.

code is now better.
now works with any number of image in the signature.

If you use old code, plz change with this new.

Thanks.
maybe should be a core feature! Wink
(2014-06-22, 03:13 PM)Eldenroot Wrote: [ -> ]maybe should be a core feature! Wink
agree
Been looking for this for ages with no luck, works really well, thanks!
awesome plug bro ty so much