Two different functions for file size
Made two different functions for file size in ImageFile; one uses the other. Also, use sprintf() for gettext msgs.
This commit is contained in:
parent
383e6c730d
commit
99d520b351
|
@ -75,7 +75,7 @@ class AvatarsettingsAction extends AccountSettingsAction
|
|||
|
||||
function getInstructions()
|
||||
{
|
||||
return _('You can upload your personal avatar. The maximum file size is '.ImageFile::maxFileSize().'.');
|
||||
return sprintf(_('You can upload your personal avatar. The maximum file size is %s.'), ImageFile::maxFileSize());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -155,7 +155,7 @@ class AvatarsettingsAction extends AccountSettingsAction
|
|||
$this->element('input', array('name' => 'MAX_FILE_SIZE',
|
||||
'type' => 'hidden',
|
||||
'id' => 'MAX_FILE_SIZE',
|
||||
'value' => ImageFile::maxFileSize(true)));
|
||||
'value' => ImageFile::maxFileSizeInt()));
|
||||
$this->elementEnd('li');
|
||||
$this->elementEnd('ul');
|
||||
|
||||
|
|
|
@ -152,7 +152,7 @@ class GrouplogoAction extends Action
|
|||
|
||||
function getInstructions()
|
||||
{
|
||||
return _('You can upload a logo image for your group. The maximum file size is '.ImageFile::maxFileSize().'.');
|
||||
return sprintf(_('You can upload a logo image for your group. The maximum file size is %s.'), ImageFile::maxFileSize());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -229,7 +229,7 @@ class GrouplogoAction extends Action
|
|||
$this->element('input', array('name' => 'MAX_FILE_SIZE',
|
||||
'type' => 'hidden',
|
||||
'id' => 'MAX_FILE_SIZE',
|
||||
'value' => ImageFile::maxFileSize(true)));
|
||||
'value' => ImageFile::maxFileSizeInt()));
|
||||
$this->elementEnd('li');
|
||||
$this->elementEnd('ul');
|
||||
|
||||
|
|
|
@ -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. The maximum file size is '.$this->maxFileSize().'.'));
|
||||
throw new Exception(sprintf(_('That file is too big. The maximum file size is %d.'), $this->maxFileSize()));
|
||||
return;
|
||||
case UPLOAD_ERR_PARTIAL:
|
||||
@unlink($_FILES[$param]['tmp_name']);
|
||||
|
@ -183,15 +183,24 @@ class ImageFile
|
|||
@unlink($this->filename);
|
||||
}
|
||||
|
||||
static function maxFileSize($return_bytes = false)
|
||||
static function maxFileSize()
|
||||
{
|
||||
$limit = min(ImageFile::strToInt(ini_get('post_max_size')), ImageFile::strToInt(ini_get('upload_max_filesize')), ImageFile::strToInt(ini_get('memory_limit')));
|
||||
$value = ImageFile::maxFileSizeInt();
|
||||
|
||||
if ($return_bytes) {
|
||||
return $limit;
|
||||
if ($value > 1024 * 1024) {
|
||||
return ($value/(1024*1024)).'Mb';
|
||||
} else if ($value > 1024) {
|
||||
return ($value/(1024)).'kB';
|
||||
} else {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
return ($limit/(1024*1024)).'MB';
|
||||
static function maxFileSizeInt()
|
||||
{
|
||||
return min(ImageFile::strToInt(ini_get('post_max_size')),
|
||||
ImageFile::strToInt(ini_get('upload_max_filesize')),
|
||||
ImageFile::strToInt(ini_get('memory_limit')));
|
||||
}
|
||||
|
||||
static function strToInt($str)
|
||||
|
|
Loading…
Reference in New Issue
Block a user