logo
Apache Lounge
Webmasters

 


About

Forum Index Downloads Search Register Log in  RSS Apache Lounge
 



Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Apache Lounge is not sponsored.

Your donations will help to keep this site alive and well, and continuing building binaries.



PHP - calculate aprox Download time

 
Post new topic   Reply to topic    Apache Forum Index -> Coding & Scripting Corner



View previous topic :: View next topic  
Author Message
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 6255
Location: Germany, Next to Hamburg

PostPosted: Sun 07 May '06 20:54    Post subject: PHP - calculate aprox Download time Reply with quote

Code:

<?php
function download_time($file) {
    if(!function_exists("sec_format")) {
        function sec_format($seconds) {
            $units = array(    "day|s"=>86400,
                            "hour|s"=>3600,
                            "minute|s"=>60,
                            "second|s"=>1
                             );
            if($seconds < 1) {
                return "< 1second";
            } else {
                $show = FALSE;
                $ausg = "";
                foreach($units as $key=>$value) {
                    $t = round($seconds/$value);
                    $seconds = $seconds%$value;
                    list($s, $pl) = explode("|", $key);
                    if($t > 0 || $show) {
                        if($t == 1) {
                            $ausg .= $t." ".$s.", ";
                        } else {
                            $ausg .= $t." ".$s.$pl.", ";
                        }
                        $show = TRUE;
                    }
                }
                $ausg = substr($ausg, 0, strlen($ausg)-2);
                return $ausg;
            }
        }
    }
    $values = array("DSL"=>768,
                    "ISDN"=>128,
                    "Modem"=>56.6
                      );
    $size = filesize($file);
    $ausg = round($size/(1024), 0)." KB<br />";
    $size *= 8;
    foreach($values as $key=>$value) {
        $time = sec_format($size/($value*1024));
        $ausg .= $time." @ ".$value." kBit (".$key.")<br />";
    }
    return $ausg;
}
echo download_time("test.zip");
?>


Sure that DSL today can be much faster, but don't be lazy and but it to the array Wink
Back to top


Post new topic   Reply to topic    Apache Forum Index -> Coding & Scripting Corner
Page 1 of 1