Advertisement
Guest User

php

a guest
Mar 23rd, 2016
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.39 KB | None | 0 0
  1. <?
  2.  
  3. function tamanho($conexao, $arquivo){
  4.  
  5. if($conexao == "56"){$kbps = "56 Kbps";}
  6. if($conexao == "128"){$kbps = "128 Kbps";}
  7. if($conexao == "256"){$kbps = "256 Kbps";}
  8. if($conexao == "512"){$kbps = "512 Kbps";}
  9. if($conexao == "1024"){$kbps = "1 Mbps";}
  10. if($conexao == "2048"){$kbps = "2 Mbps";}
  11. if($conexao == "4096"){$kbps = "4 Mbps";}
  12.  
  13. if(preg_match("/ B/", $arquivo)){$bytes = "1";}
  14. if(preg_match("/ KB/", $arquivo)){$bytes = "1024";}
  15. if(preg_match("/ MB/", $arquivo)){$bytes = "1048576";}
  16. if(preg_match("/ GB/", $arquivo)){$bytes = "1073741824";}
  17.  
  18. $arquivo = str_replace(",", ".", $arquivo);
  19. $arquivo = preg_replace("/B|KB|MB|GB/", "", $arquivo);
  20.  
  21. $seconds = ($arquivo * $bytes) / ($conexao * 1000 / 8);$units = array("segundo" => "60", "minuto" => "60", "hora" => "24", "dia" => "365", "ano" => "9999");$time = "";
  22.  
  23. // var array = [];
  24.  
  25. if($seconds > 0 and $seconds < .001){$time = "1 segundo";}else{if($seconds < 1){$time = round($seconds * 1000)." segundos";}else{if($seconds < 60){$time = number_format($seconds, 2, ".", "")." segundos";}else{$seconds = round($seconds);
  26.  
  27. // for(var unit in units){
  28. // var n = $seconds % units[unit];
  29. // $seconds -= n;
  30. // $seconds /= units[unit];
  31. // array.unshift(n + ' ' + unit + (n != 1 ? 's' : ''));
  32. // if($seconds == 0){break;}
  33. // }
  34. // $time = array.slice(0, 3).join(', ');
  35. //
  36.  
  37. }}}
  38.  
  39. return$time;}
  40.  
  41. echo tamanho("2048", "20 MB");
  42.  
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement