View Single Post
Old 12-27-2007, 11:55 PM   #4 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by Aaron View Post
When I do any php function that gets a size of something, does it measure the size in bytes? bits?
Functions like filesize return the size in bytes. The return values of all PHP functions are available in the PHP manual (there's always a section called "Return Values" with an explanation).

Quote:
Originally Posted by Aaron View Post
Does PHP have a built in function to convert these values, or do I have to write all that stuff?
It is very simple mathematics, essentially. There are hundreds of available functions available throughout the 'net which will take a byte value and convert it into any format that you want... but as a learning process I would recommend writing your own to do exactly what you want. All that are really needed are / (divide), (int) (type casting/juggling) or intval() (convert number to integer) -- or if you're feeling confident you could use shifting bitwise operators ;)

Also, on the topic of 1000 bytes versus 1024 bytes, two different systems are available for use. Using SI prefix, 1,000,000 bytes equals 1 megabyte (MB); using Binary prefix, 1,048,576 (1024 * 1024) bytes equals 1 mebibyte (MiB). Often, notably, the SI prefixes are used for both instances with the precise meaning being determined by the context in which the value is used! More information on this ambiguity can be found on Wikipedia.
Salathe is offline  
Reply With Quote