Page 1 of 1

Storing the uploaded file sizes

Posted: Sat Mar 06, 2004 4:28 pm
by therat
When uploading a file I use

Code: Select all

$_FILES['userfile']['size']
to store the size in a database. This just stores the size as a number of bytes. How do I show this as 1kb, 1mb or 1gb etc.

Posted: Sat Mar 06, 2004 6:01 pm
by vigge89
1kb = 1024 byte
1mb = 1024 kb = 1048576 b

for each increase (ie bytes to kilobytes), divide with 1024
so if you have a number in bytes, and want to show the filesize in megabytes, you should divide the number of bytes with 1048576, since 1024*1024 is equal to 1048576.

Posted: Sun Mar 07, 2004 6:07 am
by therat
Thanks, i'll give that a go.

Posted: Sun Mar 07, 2004 6:40 am
by vigge89