summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSean Murphy <sgmurphy@gmail.com>2009-02-05 14:11:50 -0500
committerSean Murphy <sgmurphy@gmail.com>2009-02-05 14:11:50 -0500
commit746a5d75071a2a7c913c522ea78f2b88b87f4ce2 (patch)
tree8ee46b606953752793fa8e446f763a5e982ead28 /lib
parent4ced74dc9105884fc05d4ab48e8d0162204f8c6a (diff)
Fixed #905: Presenting image size limit to user.
Diffstat (limited to 'lib')
-rw-r--r--lib/imagefile.php25
1 files changed, 24 insertions, 1 deletions
diff --git a/lib/imagefile.php b/lib/imagefile.php
index 5e9913235..f9f47a47e 100644
--- a/lib/imagefile.php
+++ b/lib/imagefile.php
@@ -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;
+ }
} \ No newline at end of file