summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2009-02-05 16:02:19 -0500
committerEvan Prodromou <evan@controlyourself.ca>2009-02-05 16:02:19 -0500
commit383e6c730db5808b961f53bf39868053fca1fc32 (patch)
tree02d19dc1d536653fefc5a77cfc8c392a578b0abc /lib
parent7ea136ee1ba350a64b95cd86a386f3e0d0e339d8 (diff)
parentd4bdb2dc1924e2753baa4cf1751acb08b6ed3cae (diff)
Merge branch '0.7.x' of git://gitorious.org/laconica/sgmurphy-clone into sgmurphy-clone/0.7.x
Diffstat (limited to 'lib')
-rw-r--r--lib/common.php1
-rw-r--r--lib/imagefile.php30
2 files changed, 29 insertions, 2 deletions
diff --git a/lib/common.php b/lib/common.php
index 825ba0ff7..482800876 100644
--- a/lib/common.php
+++ b/lib/common.php
@@ -24,7 +24,6 @@ define('LACONICA_VERSION', '0.7.0');
define('AVATAR_PROFILE_SIZE', 96);
define('AVATAR_STREAM_SIZE', 48);
define('AVATAR_MINI_SIZE', 24);
-define('MAX_AVATAR_SIZE', 256 * 1024);
define('NOTICES_PER_PAGE', 20);
define('PROFILES_PER_PAGE', 20);
diff --git a/lib/imagefile.php b/lib/imagefile.php
index 5e9913235..74c3d14f0 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,32 @@ class ImageFile
{
@unlink($this->filename);
}
+
+ static function maxFileSize($return_bytes = false)
+ {
+ $limit = min(ImageFile::strToInt(ini_get('post_max_size')), ImageFile::strToInt(ini_get('upload_max_filesize')), ImageFile::strToInt(ini_get('memory_limit')));
+
+ if ($return_bytes) {
+ return $limit;
+ }
+
+ 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