
Originally Posted by
Torch
Tracking bandwidth of a file is impossible through PHP without assistance of some server side application that would track outgoing transfer. In other words, impossible unless you actually own the server or have full shell access.
...
Impossible? Naa... With a few if statements you could convert this function of mine from FileVIP to update a MySQL database table row with the current amount transferred, left to trans., total trans., etc etc.
If you guys want to you could take a shot at it. I don't have time now to.
;)
PHP Code:
function sendDownload($file, $speed) {
$filename = basename($file);
$file_extension = array_pop(explode('.', $filename));
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: private");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Accept-Ranges: bytes");
$size = filesize($file);
if(isset($_SERVER['HTTP_RANGE'])) {
$seek_range = substr($_SERVER['HTTP_RANGE'], 6);
$range = explode( '-', $seek_range);
if($range[0] > 0) { $seek_start = intval($range[0]); }
if($range[1] > 0) { $seek_end = intval($range[1]); }
header("HTTP/1.1 206 Partial Content");
header("Content-Length: " . ($seek_end - $seek_start + 1));
header("Content-Range: bytes $seek_start-$seek_end/$size");
}
else {
$seekSeekSeek = $seek_end / $size;
header("Content-Range: bytes 0-$seekSeekSeek");
header("Content-Length: $size");
}
$fp = fopen($file,'rb');
fseek($fp,$seek_start);
while(!feof($fp)) {
set_time_limit(0);
print(fread($fp, (1024 * $speed)));
flush();
sleep(1);
}
fclose($fp);
exit;
}