Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/07/2003, 22:45
kech
 
Fecha de Ingreso: marzo-2003
Mensajes: 277
Antigüedad: 21 años, 1 mes
Puntos: 0
Transformando el tamaño de un archivo

quien tiene otra posibilidad para hacer este codigo
lo que hace es trasformar el tamaño de un archivo osea

201545728 esto es el tamaño del archivo
y como deberia estar
201 MB
este codigo lo hace pero quisas es muy engorroso mi pregunta se puede hacer esto con menos pasos

Código PHP:
if (strlen($torrent["info"]["length"]) >= 11){
             
$show_filesize substr($torrent["info"]["length"],0,2)."GB";
            }
        elseif (
strlen($torrent["info"]["length"]) >= 10){
             
$show_filesize substr($torrent["info"]["length"],0,1)."GB";
            }
        elseif (
strlen($torrent["info"]["length"]) >= 9){
             
$show_filesize substr($torrent["info"]["length"],0,3)."MB";
            }
        elseif (
strlen($torrent["info"]["length"]) >= 8){
             
$show_filesize substr($torrent["info"]["length"],0,2)."MB";
            }
        elseif (
strlen($torrent["info"]["length"]) >= 7){
             
$show_filesize substr($torrent["info"]["length"],0,1)."MB";
            }
        elseif (
strlen($torrent["info"]["length"]) >= ){
             
$show_filesize substr($torrent["info"]["length"],0,3)."KB";
            }
        elseif (
strlen($torrent["info"]["length"]) >= ){
             
$show_filesize substr($torrent["info"]["length"],0,2)."KB";
            }
        elseif (
strlen($torrent["info"]["length"]) >= ){
             
$show_filesize substr($torrent["info"]["length"],0,1)."KB";
            }
        else{
             
$show_filesize "0 KB";
            }

en php.net aparecen algunos ejemplos de hacerlo de otra forma pero el problema que esos solo aproximan el tamaño

osea que esto

201545728

lo transforman a

192.1 MB

salu2

Informacion de ultimo hora
ME equivoque el tema por que aparece redondeado el tamaño del archivo es por que 1 mb son 1024 kb

se me olvido jejejej

salu2

Última edición por kech; 16/07/2003 a las 08:37