Merge pull request #1703 from rabuzarus/readable_bytes

show maximagesize warning in a human readable format
2022.09-rc
fabrixxm 2015-06-29 13:50:55 +02:00
commit 17514e0d68
6 zmienionych plików z 18 dodań i 5 usunięć

Wyświetl plik

@ -1013,3 +1013,4 @@ function store_photo($a, $uid, $imagedata = "", $url = "") {
return($image); return($image);
} }

Wyświetl plik

@ -2282,3 +2282,15 @@ function deindent($text, $chr="[\t ]", $count=NULL) {
return implode("\n", $lines); return implode("\n", $lines);
} }
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];
}

Wyświetl plik

@ -785,7 +785,7 @@ function photos_post(&$a) {
$maximagesize = get_config('system','maximagesize'); $maximagesize = get_config('system','maximagesize');
if(($maximagesize) && ($filesize > $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); @unlink($src);
$foo = 0; $foo = 0;
call_hooks('photo_post_end',$foo); call_hooks('photo_post_end',$foo);

Wyświetl plik

@ -141,7 +141,7 @@ function profile_photo_post(&$a) {
$maximagesize = get_config('system','maximagesize'); $maximagesize = get_config('system','maximagesize');
if(($maximagesize) && ($filesize > $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); @unlink($src);
return; return;
} }

Wyświetl plik

@ -78,9 +78,9 @@ function wall_attach_post(&$a) {
} }
if(($maxfilesize) && ($filesize > $maxfilesize)) { 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); @unlink($src);
return; killme();
} }
$r = q("select sum(octet_length(data)) as total from attach where uid = %d ", $r = q("select sum(octet_length(data)) as total from attach where uid = %d ",

Wyświetl plik

@ -119,7 +119,7 @@ function wall_upload_post(&$a, $desktopmode = true) {
$maximagesize = get_config('system','maximagesize'); $maximagesize = get_config('system','maximagesize');
if(($maximagesize) && ($filesize > $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); @unlink($src);
killme(); killme();
} }