diff --git a/include/Photo.php b/include/Photo.php index e36fd46ca0..0adc55258b 100644 --- a/include/Photo.php +++ b/include/Photo.php @@ -1013,3 +1013,15 @@ function store_photo($a, $uid, $imagedata = "", $url = "") { return($image); } + +function formatBytes($bytes, $precision = 2) { + $units = array('B', 'KB', 'MB', 'GB', 'TB'); + + $bytes = max($bytes, 0); + $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); + $pow = min($pow, count($units) - 1); + + $bytes /= pow(1024, $pow); + + return round($bytes, $precision) . ' ' . $units[$pow]; +} diff --git a/mod/photos.php b/mod/photos.php index ca770d95aa..3ed8e9984c 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -785,7 +785,7 @@ function photos_post(&$a) { $maximagesize = get_config('system','maximagesize'); if(($maximagesize) && ($filesize > $maximagesize)) { - notice( t('Image exceeds size limit of ') . $maximagesize . EOL); + notice( sprintf(t('Image exceeds size limit of %s'), formatBytes($maximagesize)) . EOL); @unlink($src); $foo = 0; call_hooks('photo_post_end',$foo); diff --git a/mod/profile_photo.php b/mod/profile_photo.php index 6ca7c4b6d4..6607eebd0c 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -141,7 +141,7 @@ function profile_photo_post(&$a) { $maximagesize = get_config('system','maximagesize'); if(($maximagesize) && ($filesize > $maximagesize)) { - notice( sprintf(t('Image exceeds size limit of %d'), $maximagesize) . EOL); + notice( sprintf(t('Image exceeds size limit of %s'), formatBytes($maximagesize)) . EOL); @unlink($src); return; } diff --git a/mod/wall_attach.php b/mod/wall_attach.php index 646a776a4a..80b679012c 100644 --- a/mod/wall_attach.php +++ b/mod/wall_attach.php @@ -78,9 +78,9 @@ function wall_attach_post(&$a) { } if(($maxfilesize) && ($filesize > $maxfilesize)) { - notice( sprintf(t('File exceeds size limit of %d'), $maxfilesize) . EOL); + echo sprintf(t('File exceeds size limit of %s'), formatBytes($maxfilesize)) . EOL; @unlink($src); - return; + killme(); } $r = q("select sum(octet_length(data)) as total from attach where uid = %d ", diff --git a/mod/wall_upload.php b/mod/wall_upload.php index 291307b8ec..44cfa01567 100644 --- a/mod/wall_upload.php +++ b/mod/wall_upload.php @@ -119,7 +119,7 @@ function wall_upload_post(&$a, $desktopmode = true) { $maximagesize = get_config('system','maximagesize'); if(($maximagesize) && ($filesize > $maximagesize)) { - echo sprintf( t('Image exceeds size limit of %d'), $maximagesize) . EOL; + echo sprintf( t('Image exceeds size limit of %s'), formatBytes($maximagesize)) . EOL; @unlink($src); killme(); }