Chris Payne wrote:
Hi everyone,

I'm not sure of the correct formula for this, if I have a file - just
for example, that is 10245458756 bytes long and the download speed is
60KB a second, what formula would I use to calculate how many
seconds/minutes/hours it would take to download the file?

Maths really isn't my strong point and formulas go over my head
otherwise I wouldn't ask :-(

Thanks everyone

Chris

$size = 1024548756; // in bytes
$kb_per_sec = 60;   // I assume you'll fill these in from elsewhere?

$b_per_sec = $kb_per_sec * 1024;

$seconds = $size / $b_per_sec;
$minutes = 0;
$hours = 0;

if($seconds > 60)
{
  // 60 seconds to a minute
  $minutes = (int)($seconds / 60);
  $seconds -= $minutes * 60;

  if($minutes > 60)
  {
    // 60 minutes to an hour
    $hours = (int)($minutes / 60);
    $minutes -= $hours * 60;

    // if you want to go further and calculate days, have at :)
  }
}

You could also approach this using modulus, but if you're not confident with math, this might be a more intuitive approach.

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

Reply via email to