Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: PHP - calculate aprox Download time |
|
Author |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7374 Location: Germany, Next to Hamburg
|
Posted: Sun 07 May '06 20:54 Post subject: PHP - calculate aprox Download time |
|
|
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 |
|
Back to top |
|
|
|
|
|
|