File Upload Size

Install and configure FormaLMS and DoceboCE
Post Reply
pretheesh.j
Newbie
Posts: 11
Joined: Tue Jul 14, 2015 5:57 am

File Upload Size

Post by pretheesh.j »

While uploading documents(Documents Upload section) from course add/edit page, we have restrictions based on uploading file size. I have checked the code to generate the form fields and find out the below code was generating max upload file size label. Here, the code was fetching the max upload size values from PHP.INI file. But the code was not checking weather the values in MB or GB. Instead of that its directly labeling as 'Mb'.

Code
=======
public static function getFilefield( $label_name, $id, $name, $value = '', $alt_name = '', $other_after = '', $other_before = '', $other_afterbefore = '' ) {

if( $alt_name == '' ) $alt_name = strip_tags($label_name);

$p_size = intval(ini_get('post_max_size'));
$u_size = intval(ini_get('upload_max_filesize'));
$max_kb = ( $p_size < $u_size ? $p_size : $u_size );
$other_after = ' (Max. '.$max_kb.' Mb) '.$other_after;
return Form::getLineFilefield( 'form_line_l', 'floating', $label_name, 'fileupload', $id, $name, $value, $alt_name, '', $other_after, $other_before, $other_afterbefore );

}

Thanks..
jasmines
Senior Boarder
Posts: 277
Joined: Fri May 03, 2013 12:29 pm

Re: File Upload Size

Post by jasmines »

in /lib/lib.form.php change:

Code: Select all

$p_size = intval(ini_get('post_max_size'));
$u_size = intval(ini_get('upload_max_filesize'));
$max_kb = ( $p_size < $u_size ? $p_size : $u_size );
$other_after = ' (Max. '.$max_kb.' Mb) '.$other_after;
with:

Code: Select all

$p_size = ini_get('post_max_size');
		$u_size = ini_get('upload_max_filesize');
		$p_unit = substr($p_size, -1);
		$u_unit = substr($u_size, -1);
		if(!is_numeric($p_unit))
		{$p_size = substr($p_size, 0, -1);}
		if(!is_numeric($u_unit))
		{$u_size = substr($u_size, 0, -1);}
		$p_size_normalized = $p_size;
		switch(strtoupper($p_unit)) {
			case 'G':
				$p_size_normalized *= 1024;
			case 'M':
				$p_size_normalized *= 1024;
			case 'K':
				$p_size_normalized *= 1024;		
		}
		$u_size_normalized = $u_size;
		switch(strtoupper($u_unit)) {
			case 'G':
				$u_size_normalized *= 1024;
			case 'M':
				$u_size_normalized *= 1024;
			case 'K':
				$u_size_normalized *= 1024;		
		}
		
		$max_kb = ( $p_size_normalized < $u_size_normalized ? $p_size : $u_size );
		$unit = ( $p_size_normalized < $u_size_normalized ? $p_unit : $u_unit );
		
		$other_after = ' (Max. '.$max_kb.' '.$unit.'b) '.$other_after;
Similar changes (not exactly the same) are needed in /appCore/modules/newsletter/newsletter.php and /appLms/modules/public_newsletter_admin/public_newsletter_admin.php but you should be able to do by yourself.
Post Reply