Storing the uploaded file sizes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
therat
Forum Commoner
Posts: 62
Joined: Wed Oct 01, 2003 2:44 pm
Location: London

Storing the uploaded file sizes

Post 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.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post 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.
therat
Forum Commoner
Posts: 62
Joined: Wed Oct 01, 2003 2:44 pm
Location: London

Post by therat »

Thanks, i'll give that a go.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

Post Reply