You are here: Re: File Size Conversion « PHP Programming Language « IT news, forums, messages
Re: File Size Conversion

Posted by Jaak on 10/08/91 11:36

This is what I use.
Maybe not so complicated, but more easy readable. It gives 0.6Mb instead of
600 kb etc Off course you can expand this with Gb etc...

if ($filesize < 500)
{
$filesize = "$grootte b";
}
elseif ($filesize <((1024 * 1024)/2))
{
$filesize = round ($filesize / 1024,1);
$filesize = "$filesize Kb";
}
else
{
$filesize = round (($filesize / 1024 / 1024),2);
$filesize = "$filesize Mb";
}


"James Wheaton" <apoc_gfx@yahoo.com> schreef in bericht
news:cZ_uf.685049$_o.478491@attbi_s71...
> Here's a function a wrote for a previous program:
>
> /****************************
> * File size unit converter *
> ****************************/
> function fsize_unit_convert($bytes)
> {
> $units = array('b', 'kb', 'mb', 'gb');
> $converted = $bytes . ' ' . $units[0];
> for ($i = 0; $i < count($units); $i++)
> {
> if (($bytes/pow(1024, $i)) >= 1)
> {$converted = round($bytes/pow(1024, $i), 2) . ' ' . $units[$i];}
> }
> return $converted;
> }
>
> Java Boy wrote:
>
>> 1 KB == 1024 bytes
>> rest you can figure out yourself
>>
>> --
>> Geeks Home
>> www.fahimzahid.com
>>
>>
>>
>>
>> "Prince of Code" <princeofcode@gmail.com> wrote in message
>> news:1134977390.809166.140530@o13g2000cwo.googlegroups.com...
>>> Can anybody help me out by writing a function for the given problem
>>>
>>> Write a function in PHP that converts given number of bytes into
>>> Readabel format like 99.92 KB for 102323 bytes and
>>> 3 MB for 3072 bytes and so on. Let your function be
>>> sophasticated,portable,easy readable.
>>>
>>> Thankzz in advance
>>> Napoleon
>>>
>
> --
> http://www.uranther.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация