Boa noite galera, é o seguinte, tenho um script funcionando perfeitamente em javascript, onde você coloca a conexão e o tamanho do arquivo e ele informa o tempo estimado para baixar este arquivo, só que eu queria que funcionasse em PHP, alguém ai consegue transformar ou reprogramar o código para funções em PHP? segue o código:
function tamanho(conexao, arquivo) { if (conexao == "56") { c = "56 Kbps"; } if (conexao == "128") { c = "128 Kbps"; } if (conexao == "256") { c = "256 Kbps"; } if (conexao == "512") { c = "512 Kbps"; } if (conexao == "1024") { c = "1 Mbps"; } if (conexao == "2048") { c = "2 Mbps"; } if (conexao == "4096") { c = "4 Mbps"; } if (arquivo.match(" B")) { d = "1"; } if (arquivo.match(" KB")) { d = "1024"; } if (arquivo.match(" MB")) { d = "1048576"; } if (arquivo.match(" GB")) { d = "1073741824"; } arquivo = arquivo.replace(",", "."); arquivo = arquivo.replace(RegExp("B|KB|MB|GB"), ""); var e = (arquivo * d) / (conexao * 1000 / 8); var f = { segundo: 60, minuto: 60, hora: 24, dia: 365, ano: Number.MAX_VALUE }; var g = ''; var h = []; if (e > 0 && e < .001) { g = '1 segundo' } else { if (e < 1) { g = Math.round(e * 1000) + ' segundos' } else { if (e < 60) { g = e.toFixed(2) + ' segundos' } else { e = Math.round(e); for (var unit in f) { var n = e % f[unit]; e -= n; e /= f[unit]; h.unshift(n + ' ' + unit + (n != 1 ? 's' : '')); if (e == 0) { break } } g = h.slice(0, 3).join(' e ') } } } document.write("<b>" + c + "</b> - " + g + "<br>") }
Estarei no aguardo, abraços gente.
Galera consegui até onde não está comentado, não consigo mais, olhem como ficou:
<? function tamanho($conexao, $arquivo){ if($conexao == "56"){$kbps = "56 Kbps";} if($conexao == "128"){$kbps = "128 Kbps";} if($conexao == "256"){$kbps = "256 Kbps";} if($conexao == "512"){$kbps = "512 Kbps";} if($conexao == "1024"){$kbps = "1 Mbps";} if($conexao == "2048"){$kbps = "2 Mbps";} if($conexao == "4096"){$kbps = "4 Mbps";} if(preg_match("/ B/", $arquivo)){$bytes = "1";} if(preg_match("/ KB/", $arquivo)){$bytes = "1024";} if(preg_match("/ MB/", $arquivo)){$bytes = "1048576";} if(preg_match("/ GB/", $arquivo)){$bytes = "1073741824";} $arquivo = str_replace(",", ".", $arquivo); $arquivo = preg_replace("/B|KB|MB|GB/", "", $arquivo); $seconds = ($arquivo * $bytes) / ($conexao * 1000 / 8);$units = array("segundo" => "60", "minuto" => "60", "hora" => "24", "dia" => "365", "ano" => "9999");$time = ""; // var array = []; 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); // for(var unit in units){ // var n = $seconds % units[unit]; // $seconds -= n; // $seconds /= units[unit]; // array.unshift(n + ' ' + unit + (n != 1 ? 's' : '')); // if($seconds == 0){break;} // } // $time = array.slice(0, 3).join(', '); // }}} return$time;} echo tamanho("2048", "20 MB"); ?>
Ninguém?