转换并计算限制和使用情况,然后将其显示在消息中

问题描述 投票:0回答:1

嗨,我正在使用带有codeigniter的imap。我试图得到我的imap使用和限制消息就像谷歌有收件箱它有一个百分比显示像

0.07 GB (0%) of 15 GB used

目前我只能让我的一个显示像

(455112.26830953%) of 2.00 GB used

问题:如何确保我可以让imap计算限制和使用正确并将其显示在消息中。

当我回复所有电子邮件qazxsw poi的总大小时,输出为471858

$count
php codeigniter imap
1个回答
1
投票

你的计算是落后的。您需要将if (isset($results)) { if ($order == 'DESC') { $lists = array_reverse($results); } $count = 0; foreach ($lists as $overview) { $count += $overview->size; if (isset($overview->subject)) { echo $overview->msgno ." ". $overview->date ." ". $overview->from ." ". $overview->subject . "<br/>"; } else { echo $overview->msgno ." ". $overview->date ." ". $overview->from ." ". "No Subject<br/>"; } } // returns the total email sizes echo $count; echo "<br/><br/>"; $quota = imap_get_quotaroot($mbox, "INBOX"); $message = $quota['MESSAGE']; $percentage = ($message['limit'] / $count) * 100; echo "(" . $percentage . "%) of " . $this->byte_convert($message['limit']) . " used"; } function byte_convert($size) { # size smaller then 1kb if ($size < 1024) return $size . ' Byte'; # size smaller then 1mb if ($size < 1048576) return sprintf("%4.2f KB", $size/1024); # size smaller then 1gb if ($size < 1073741824) return sprintf("%4.2f MB", $size/1048576); # size smaller then 1tb if ($size < 1099511627776) return sprintf("%4.2f GB", $size/1073741824); # size larger then 1tb else return sprintf("%4.2f TB", $size/1073741824); } 除以$count而不是相反:

$message['limit']

然后,您只需将// 2 GB = 2147483648 bytes $percentage = ($message['limit'] / $count) * 100; // (2147483648 / 471858) * 100 = 455112% = incorrect $percentage = ($count / $message['limit']) * 100; // (471858 / 2147483648) * 100 = 0.02% = correct 添加到输出中即可获得与Gmail相同的显示:

$this->byte_convert($count)
© www.soinside.com 2019 - 2024. All rights reserved.