I'm trying to count total bandwidth usage per download.
For a example if I'm sending a 100 mb file to a user and the user disconnects/stops downloading half way so actually only 50 mb being used. Is there a way to track this?
I found this example in a tutorial and in a question on sof.
if ($fd = fopen ($fullPath, "r")) {
//the next part outputs the file
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=".$path_parts["basename"]."");
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
fclose ($fd);
and