Re: How to count transfered kBytes in File-Download

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Michelle Konzack wrote:
Hello *,

currently I have a function:

----[ '/usr/share/tdphp-vserver/includes/02_functions.inc' ]------------
<snip>
function fncPushBinary($type='show', $file, $mime='') {

Outside your function, or in, I don't care, define a variable/constant that will be used as a buffer size.

$buffer = 1024;

  if ( is_file("$file") ) {
    if ($mime == '') {
      $mime=exec("file -i -b $file");
    }
    $STRG="; filename=\"" . basename($file) . "\"";

Don't do the following...

XXXX>     $FSIZE=filesize("$file");



    if ($type == 'show') {
      header("Content-Disposition: inline" . $STRG );
    } else {
      header("Content-Disposition: attachment" . $STRG);
    }
    header("Content-Type: " . $mime);
    $HANDLER=fopen("$file", r);

Then here, do this...

$current_size = 0;
while ( !feof($HANDLER) ) {
	$current_size += $buffer;
	echo fread($HANDLE, $buffer);
}

Now, do what you want with $current_size

Maybe have a variable that you check it against that contains the users allow amount of transfer...

$current_size = 0;
while ( !feof($HANDLER) && $current_size < $allowed_limit ) {
	$current_size += $buffer;
	echo fread($HANDLE, $buffer);
}

Hope this gets you leading down the right path...

    echo fread($HANDLER, $FSIZE);
    fclose($HANDLER);
    exit();
  } else {
    $ERRNO=2;
    $ERRTX=sprintf( T_gettext("The requested binary file does not exist.<p>%s"), $file );
    fncError($ERRNO, $ERRTX, $ERRPAGE);
  }
}
<snip>
------------------------------------------------------------------------

which I want to modify it to count the kBytes a user download and  block
after a definde amount...

(there are too many peoples in the world which want to suck anything for
free and unlimited and no one cares who pay the stuff...  even if I have
100 TByte free traffic on one of my bigger servers)

My problem is now

1) how to count partial downloads
2) how to allow users to make partial downloads

any suggestions?

Oh, I should note, that the URL's looks like:

    /?what=music&where=h&section=foo&name=I_love_php5.ogg

and the input to the function is already sanitized.

Thanks, Greetings and nice Day/Evening
    Michelle Konzack
    Systemadministrator
    24V Electronic Engineer
    Tamay Dogan Network
    Debian GNU/Linux Consultant




--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux