MiCR0 Posted June 8, 2008 Share Posted June 8, 2008 I am trying to work out the maths to build 2 functions download and upload any help would be great. trying to work out how long it would take to download a file with there connection speed, as in time()+5000 until file would be finished. Here is some of the speeds function GetSpeed($Speed) $SPEEDS[ 1] = array('DownSpeed' => 56000, 'UpSpeed' => 48000, 'NAME' => 'Modem 56k (V.92)'); $SPEEDS[ 2] = array('DownSpeed' => 64000, 'UpSpeed' => 64000, 'NAME' => 'ISDN 64k'); $SPEEDS[ 3] = array('DownSpeed' => 128000, 'UpSpeed' => 128000, 'NAME' => 'ISDN 128k'); $SPEEDS[ 4] = array('DownSpeed' => 1544000, 'UpSpeed' => 1544000, 'NAME' => 'T1'); return $SPEEDS[$Speed]; $speed = GetSpeed(1); //$filedetails->size // files size in bytes $speed['DownSpeed']/1024?? lost Quote Link to comment Share on other sites More sharing options...
MiCR0 Posted June 8, 2008 Author Share Posted June 8, 2008 Maybe I should have posted this in the PHP Maths area if so sorry. Quote Link to comment Share on other sites More sharing options...
corbin Posted June 8, 2008 Share Posted June 8, 2008 Well.... If you have time (in seconds) = size/speed... You just need to get size and speed in the same unit... (both in bytes or both in KB... so on) So, it looks like you have the values in kilobits... Unless you're going to be using large numbers, you might as well just divide in bytes, since that's what filesize() will return... For example: //pretend $filesize is the size of a certain file $dialup = GetSpeed(1); $time = $filesize/($dialup['DownSpeed']/1024*; echo "It would take {$time} seconds to download the file on dialup."; Why the /1024*8? Well, with kilobits... A bit is 8 bytes, and kilo means 1024 (well.... in the world of computers for simplicity ;p)... So, if you want it to kilobytes you have to do times 8. Then, if you want it in bytes, you have to drop the kilobytes... In other words divide by 1024. Quote Link to comment Share on other sites More sharing options...
MiCR0 Posted June 8, 2008 Author Share Posted June 8, 2008 Thank mate Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.