Skip to content

Commit dc37335

Browse files
committed
v.6.1
Fixed elapsed time showing wrong string
1 parent befb66e commit dc37335

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

upload.php

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# @Date: 2020/11/15 02:49:02
55
# @Email: its@hpv.im
66
# @Last modified by: Amirhosseinhpv
7-
# @Last modified time: 2021/05/19 12:30:19
7+
# @Last modified time: 2021/05/19 12:40:35
88
# @License: GPLv2
99
# @Copyright: Copyright © 2020 Amirhosseinhpv, All rights reserved.
1010
?>
@@ -25,7 +25,7 @@
2525
ob_implicit_flush(true);
2626
ob_start();
2727
echo "<script>document.title = 'Uploading ...'; document.querySelector('h1').innerHTML += '<div style=\"font-size: 0;margin-top: 3rem;\"><small style=\"font-size: 1rem;font-family: initial;font-weight: initial;\">Transferring <u>{$url}</u> as <strong>{$name}</strong><br><span style=\"margin-top: 1rem;display: block;\">Please wait until process complete or Press ESC key to cancel</span></small></div><div id=\"progress\"></div>';</script>";
28-
$time = strtotime('now');
28+
$time = microtime(true);
2929
$remote = fopen($url, 'r');
3030
$local = fopen($name, 'w');
3131
$headers = get_headers($url, true);
@@ -79,22 +79,12 @@ function human_filesize($bytes, $decimals = 2)
7979
}
8080
function human_timing($time)
8181
{
82-
$time = time() - $time; // to get the time since that moment
83-
$time = ($time<1)? 1 : $time;
84-
$tokens = array (
85-
31536000 => 'year',
86-
2592000 => 'month',
87-
604800 => 'week',
88-
86400 => 'day',
89-
3600 => 'hour',
90-
60 => 'minute',
91-
1 => 'second'
92-
);
93-
foreach ($tokens as $unit => $text) {
94-
if ($time < $unit) continue;
95-
$numberOfUnits = floor($time / $unit);
96-
return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
97-
}
82+
$s = microtime(true) - $time;
83+
$h = floor($s / 3600);
84+
$s -= $h * 3600;
85+
$m = floor($s / 60);
86+
$s -= $m * 60;
87+
return ($h > 0 ? "$h:" : "") .sprintf('%02d', $m).':'.sprintf('%02d', $s);
9888
}
9989
?>
10090
<form style="margin-top: 1rem;" name='upload' method='post' action="<?php echo strtok($_SERVER['REQUEST_URI'], '?');?>">

0 commit comments

Comments
 (0)