Fixed #905: Presenting image size limit to user.

This commit is contained in:
Sean Murphy 2009-02-05 14:11:50 -05:00
parent 4ced74dc91
commit 746a5d7507
3 changed files with 26 additions and 3 deletions

View File

@ -75,7 +75,7 @@ class AvatarsettingsAction extends AccountSettingsAction
function getInstructions()
{
return _('You can upload your personal avatar.');
return _('You can upload your personal avatar. The maximum file size is '.ImageFile::maxFileSize().'.');
}
/**

View File

@ -152,7 +152,7 @@ class GrouplogoAction extends Action
function getInstructions()
{
return _('You can upload a logo image for your group.');
return _('You can upload a logo image for your group. The maximum file size is '.ImageFile::maxFileSize().'.');
}
/**

View File

@ -72,7 +72,7 @@ class ImageFile
break;
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
throw new Exception(_('That file is too big.'));
throw new Exception(_('That file is too big. The maximum file size is '.$this->maxFileSize().'.'));
return;
case UPLOAD_ERR_PARTIAL:
@unlink($_FILES[$param]['tmp_name']);
@ -182,4 +182,27 @@ class ImageFile
{
@unlink($this->filename);
}
static function maxFileSize()
{
$limit = min(ImageFile::strToInt(ini_get('post_max_size')), ImageFile::strToInt(ini_get('upload_max_filesize')));
return ($limit/(1024*1024)).'MB';
}
static function strToInt($str)
{
$unit = substr($str, -1);
$num = substr($str, 0, -1);
switch(strtoupper($unit)){
case 'G':
$num *= 1024;
case 'M':
$num *= 1024;
case 'K':
$num *= 1024;
}
return $num;
}
}