如何从PHP文件/var/mail/.../maildirsize获取邮件目录大小?
maildirsize的格式如下:
20971520S,0C // quota storage, quota messages
1195 1 // size in bytes, message added
1687 1 // size in bytes, message added
-1195 -1 // size in bytes, message removed
现在我编写了自己的函数来获取maildirsize的总字节数和总消息数。但是当我在服务器上删除maildirsize时,它只显示正确的值,在我的邮件帐户中重新登录,以便新生成文件maildirsize。有什么想法吗?
function calculateMaildirsize()
{
$total_bytes = 0;
$total_messages = 0;
$lines = file ('maildirsize');
foreach ($lines as $index => $line) {
// Ignore Storage Quota and Message Quota $line[0]
if($index > 0) {
$line_value_bytes = explode(' ', $line)[0];
$line_value_messages = explode(' ', $line)[1];
$total_bytes += $line_value_bytes;
$total_messages += $line_value_messages;
}
}
$maildirsize = array('total_bytes' => $total_bytes,
'total_messages' => $total_messages);
return $maildirsize;
}
// Evoke the calculation function
$result = calculateMaildirsize();
// Output result
foreach($result as $key => $value) {
echo $key." => ".$value."<br>\n";
}
答案 0 :(得分:0)
也许这对你有用:
<?php
$f = 'path/to/mail';
$io = popen ( '/usr/bin/du -sk ' . $f, 'r' );
$size = fgets ( $io, 4096);
$size = substr ( $size, 0, strpos ( $size, "\t" ) );
pclose ( $io );
echo 'Directory: ' . $f . ' => Size: ' . $size;
?>
我前段时间在此处找到它并将其用于类似目的 - php get directory size
我希望这有帮助!