Ok, I think this will do it. This function takes 2 arguments. The first is location of log file and second is total bandwidth (IN BYTES), default is 2GB. It will print a table of used and left bandwidth, with a progress bar. I think you can take it from here and tweak it.
There is another function called convert_bytes() which just converts bytes to the closest range.
function process_bandwidth($log, $bandwidth=2147483648)
{
// Check argument input
if (!is_string($log)) return(false);
if (!is_numeric($bandwidth)) return(false);
// Read the log file into an array
// Return false if it couldn't
if (($file = file($log)) === false) {
return(false);
}
// Convert each string line into a number
foreach ($file as $key => $val) {
settype($file[$key], 'float');
}
// Get total bytes
$bytes = array_sum($file);
// Get percent used of bandwidth
$percent = ($bytes / $bandwidth) * 100;
$percent = round($percent, 0);
// Print table for progress bar and info
print('<table cellpadding="1" cellspacing="0" width="250">' . "\r\n");
print(' <tr align="center" style="font-size:10px;">' . "\r\n");
if ($percent <= 0) {
print(' <td colspan="2" bgcolor="#DEDEDE" style="border-left:1px solid #CC0000;"> </td>' . "\r\n");
} elseif ($percent >= 100) {
print(' <td colspan="2" bgcolor="#CC0000"> </td>' . "\r\n");
} else {
print(' <td width="' . $percent . '%" bgcolor="#CC0000"> </td>' . "\r\n");
print(' <td bgcolor="#DEDEDE"> </td>' . "\r\n");
}
print(' </tr>' . "\r\n");
print(' <tr>' . "\r\n");
print(' <td colspan="2">');
print('Used: ' . convert_bytes($bytes) . ' of ' . convert_bytes($bandwidth) . ' = ' . $percent . '%');
print('</td>' . "\r\n");
print(' </tr>' . "\r\n");
print(' <tr>' . "\r\n");
print(' <td colspan="2">');
print('Left: ' . convert_bytes($bandwidth - $bytes) . ' or ' . (100 - $percent) . '%');
print('</td>' . "\r\n");
print(' </tr>' . "\r\n");
print('</table>' . "\r\n");
}
function convert_bytes($bytes) {
if ($bytes >= 1099511627776) {
$return = round($bytes / 1024 / 1024 / 1024 / 1024, 2);
$suffix = 'TB';
} elseif ($bytes >= 1073741824) {
$return = round($bytes / 1024 / 1024 / 1024, 2);
$suffix = 'GB';
} elseif ($bytes >= 1048576) {
$return = round($bytes / 1024 / 1024, 2);
$suffix = 'MB';
} elseif ($bytes >= 1024) {
$return = round($bytes / 1024, 2);
$suffix = 'KB';
} else {
$return = $bytes;
$suffix = 'Byte';
}
if ($return == 1) {
$return .= $suffix;
} else {
$return .= $suffix . 's';
}
return $return;
}
process_bandwidth('');